See social network users cryptocurrency addresses and balances. Powered by transparent blockchains. https://iseeyour.cash
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

140 lines
6.5 KiB

from nitter_crypto import api as nitter
from pymongo import MongoClient
#import motor.motor_tornado
from datetime import datetime
import asyncio
import os
connString = str(os.environ.get('MONGODB_CONNSTRING'))
client = MongoClient(connString, connect=False)
def updateCreateUser(username):
#client = motor.motor_tornado.MotorClient(connection, serverSelectionTimeoutMS=5000)
db = client.iseeyourcash
usersDB = db.users
addressesDB = db.addresses
# If the user <username> does not exist in the database,
# it is created with the found addresses.
# Otherwise, the user and the addresses are updated
# Get the addresses for the username in async function
addresses, last_tweet_hash = nitter.getProfileAddresses(username)
if addresses == -1:
return -1
# If the user is not in the database
if not usersDB.find_one({"username": username}):
# New user initialization
newUser = {
"username": "username",
"addresses": {
"btc": [],
"eth": [],
"xno": []
},
"last_tweet_hash": "",
"last_check": "2022-05-10T16:13:41.883637"
}
newUser['username'] = username
newUser['last_tweet_hash'] = last_tweet_hash
newUser['last_check'] = datetime.utcnow().strftime('%Y-%m-%dT%H:%M')
# For each currency
for currency in addresses.keys():
# If there are found addresses
if len(addresses[currency]) > 0:
# For each currency address
for a in addresses[currency]:
# If the addres has not already been added
if not a[0].lower() in newUser['addresses'][currency]:
# We add it to the user currency addresses list
# If the address is not in the addresses DB, we create it
if not addressesDB.find_one({'address': a[0].lower()}):
newAddress = {
"address": "",
"users": [],
"balance": 0,
"currency": "",
"urls": []
}
newAddress['address'] = a[0].lower()
newAddress['users'].append(username)
newAddress['currency'] = currency
newAddress['urls'].append(a[1])
addressesDB.insert_one(newAddress)
# Else, we update the URLs with the new URLs we found.
else:
updateAddress = addressesDB.find_one({'address': a[0].lower()})
if not addressesDB.find_one({'address': a[0].lower(), 'url': a[1]}):
updateAddress['urls'].append(a[1])
if not addressesDB.find_one({'users': username, 'address': a[0].lower()}):
updateAddress['users'].append(username)
newUser['addresses'][currency].append(a[0].lower())
else:
if addressesDB.find_one({'address': a[0].lower()}):
if not addressesDB.find_one({'urls': a[1]}):
updateAddress = addressesDB.find_one({'address': a[0].lower()})
updateAddress['urls'].append(a[1])
addressesDB.update_one({"address":a[0].lower()}, {"$set": {"urls": updateAddress['urls']}})
# Insert to the database
usersDB.insert_one(newUser)
# If the user is found in the database
else:
# We retrieve the user from the database
updateUser = usersDB.find_one({"username": username})
# Update the last_check value
updateUser['last_check'] = datetime.utcnow().strftime('%Y-%m-%dT%H:%M')
# For each currency
for currency in addresses.keys():
# If there are found addresses
if len(addresses[currency]) > 0:
# For each currency address
for a in addresses[currency]:
# If the address has is already present we skip
if a[0].lower() in str(updateUser['addresses'][currency]):
if addressesDB.find_one({'address': a[0].lower()}):
if not addressesDB.find_one({'urls': a[1]}):
updateAddress = addressesDB.find_one({'address': a[0].lower()})
updateAddress['urls'].append(a[1])
addressesDB.update_one({"address":a[0].lower()}, {"$set": {"urls": updateAddress['urls']}})
continue
# Else we update the address list
# If the address is already in the database, we update
if addressesDB.find_one({'address': a[0].lower()}):
updateAddress = {
"address": "",
"users": [],
"balance": 0,
"currency": "",
"urls": []
}
updateAddress['users'].append(username)
updateAddress['urls'].append(a[1])
addressesDB.update_one({"address":a[0].lower()}, {"$set": {"urls": updateAddress['urls']}})
addressesDB.update_one({"address":a[0].lower()}, {"$set": {"users": updateAddress['users']}})
updateUser['addresses'][currency].append(a[0].lower())
# Update the user data
if last_tweet_hash:
result = usersDB.update_one({"username":username}, {"$set": {"last_tweet_hash": last_tweet_hash}})
result = usersDB.update_one({"username":username}, {"$set": {"addresses": updateUser['addresses']}})
result = usersDB.update_one({"username":username}, {"$set": {"last_check": updateUser['last_check']}})
# Defining main function
#'''
#def main():
# updateCreateUser("kycnot")
#
#
# Using the special variable
# __name__
#if __name__=="__main__":
# main()
#'''