|
|
@ -1,6 +1,7 @@
|
|
|
|
import requests
|
|
|
|
import requests
|
|
|
|
from flask import Blueprint
|
|
|
|
from flask import Blueprint
|
|
|
|
from secrets import token_urlsafe
|
|
|
|
from secrets import token_urlsafe
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
from suchwowx.factory import db
|
|
|
|
from suchwowx.factory import db
|
|
|
|
from suchwowx.helpers import get_eth_contract
|
|
|
|
from suchwowx.helpers import get_eth_contract
|
|
|
@ -74,53 +75,52 @@ def sync_avax():
|
|
|
|
print(e)
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @bp.cli.command('sync-remotes')
|
|
|
|
@bp.cli.command('sync-remotes')
|
|
|
|
# def sync_remotes():
|
|
|
|
def sync_remotes():
|
|
|
|
# """
|
|
|
|
"""
|
|
|
|
# Sync remote servers with local database.
|
|
|
|
Sync remote servers with local database.
|
|
|
|
# """
|
|
|
|
"""
|
|
|
|
# remotes = Remote.query.filter(Remote.paused == False)
|
|
|
|
from pprint import pprint
|
|
|
|
# for remote in remotes:
|
|
|
|
remotes = Remote.query.filter(Remote.paused == False)
|
|
|
|
# deets = request.get(remote.endpoint + '/api/v1/memes').json()
|
|
|
|
for remote in remotes:
|
|
|
|
# meme_exists = Meme.query.filter(Meme.meta_ipfs_hash == deets['meta_ipfs_hash']).first() # noqa
|
|
|
|
print(f'[+] Fetching approved memes from remote {remote.id} ({remote.endpoint})')
|
|
|
|
# user_exists = User.query.filter(User.public_address == deets[4].lower()).first() # noqa
|
|
|
|
deets = requests.get(remote.endpoint + '/api/v1/memes').json()
|
|
|
|
# if meme_exists:
|
|
|
|
for meme_id in deets:
|
|
|
|
# if not meme_exists.minted:
|
|
|
|
meme = deets[meme_id]
|
|
|
|
# meme_exists.minted = True
|
|
|
|
user = meme['user']
|
|
|
|
# db.session.commit()
|
|
|
|
meme_exists = Meme.query.filter(Meme.meta_ipfs_hash == meme['meta_ipfs_hash']).first() # noqa
|
|
|
|
# print(f'[+] Marked existing meme {meme_exists.id} as minted')
|
|
|
|
user_exists = User.query.filter(User.public_address == user['public_address'].lower()).first() # noqa
|
|
|
|
# else:
|
|
|
|
if not meme_exists:
|
|
|
|
# print(deets)
|
|
|
|
if not user_exists:
|
|
|
|
# if not user_exists:
|
|
|
|
user_exists = User(
|
|
|
|
# user_exists = User(
|
|
|
|
public_address=user['public_address'].lower(),
|
|
|
|
# public_address=deets[4].lower()
|
|
|
|
bio=user['bio'],
|
|
|
|
# )
|
|
|
|
ipfs_hash=user['ipfs_hash'],
|
|
|
|
# db.session.add(user_exists)
|
|
|
|
profile_image=user['profile_image'],
|
|
|
|
# db.session.commit()
|
|
|
|
website_url=user['website_url'],
|
|
|
|
# user_exists.handle = f'anon{user_exists.id}-{token_urlsafe(6)}'
|
|
|
|
wownero_address=user['wownero_address'],
|
|
|
|
# db.session.commit()
|
|
|
|
handle=user['handle']
|
|
|
|
# print(f'[+] Created user {user_exists.handle}')
|
|
|
|
)
|
|
|
|
# res = requests.get(f'{config.IPFS_SERVER}/ipfs/{deets[5]}', timeout=30).json()
|
|
|
|
db.session.add(user_exists)
|
|
|
|
# if not 'image' in res:
|
|
|
|
db.session.commit()
|
|
|
|
# print('No image IPFS hash, skipping')
|
|
|
|
print(f'[+] Created user {user_exists.handle}')
|
|
|
|
# continue
|
|
|
|
print(f'[+] Downloading image hash {meme["meme_ipfs_hash"]} as {meme["file_name"]}')
|
|
|
|
# meme_ipfs_hash = res['image'].split('ipfs://')[1]
|
|
|
|
r = requests.get(f'{config.IPFS_SERVER}/ipfs/{meme["meme_ipfs_hash"]}', stream=True)
|
|
|
|
# filename = token_urlsafe(24)
|
|
|
|
with open(f'{config.DATA_FOLDER}/uploads/{meme["file_name"]}', 'wb') as f:
|
|
|
|
# print(f'[+] Downloading image hash {meme_ipfs_hash} as {filename}')
|
|
|
|
for chunk in r.iter_content(chunk_size = 16*1024):
|
|
|
|
# r = requests.get(f'{config.IPFS_SERVER}/ipfs/{meme_ipfs_hash}', stream=True)
|
|
|
|
f.write(chunk)
|
|
|
|
# with open(f'{config.DATA_FOLDER}/uploads/{filename}', 'wb') as f:
|
|
|
|
meme = Meme(
|
|
|
|
# for chunk in r.iter_content(chunk_size = 16*1024):
|
|
|
|
title=meme['title'],
|
|
|
|
# f.write(chunk)
|
|
|
|
file_name=meme['file_name'],
|
|
|
|
# meme = Meme(
|
|
|
|
description=meme['description'],
|
|
|
|
# title=res['name'],
|
|
|
|
user_id=user_exists.id,
|
|
|
|
# file_name=filename,
|
|
|
|
meta_ipfs_hash=meme['meta_ipfs_hash'],
|
|
|
|
# description=res['description'],
|
|
|
|
meme_ipfs_hash=meme['meme_ipfs_hash'],
|
|
|
|
# user_id=user_exists.id,
|
|
|
|
minted=meme['minted'],
|
|
|
|
# meta_ipfs_hash=deets[5],
|
|
|
|
synced=True
|
|
|
|
# meme_ipfs_hash=meme_ipfs_hash,
|
|
|
|
)
|
|
|
|
# minted=True,
|
|
|
|
db.session.add(meme)
|
|
|
|
# synced=True
|
|
|
|
db.session.commit()
|
|
|
|
# )
|
|
|
|
print(f'[+] Added new meme {meme.id}')
|
|
|
|
# db.session.add(meme)
|
|
|
|
remote.last_sync_date = datetime.utcnow()
|
|
|
|
# db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
# print(f'[+] Added new meme {meme.id}')
|
|
|
|
|
|
|
|