def sum_of_hashrate(): contracts = [] address = request.json.get("address") mycryptoheroes_records = mongo.db.mycryptoheroes.find( {"owner_addresses": address}) mycryptoheroes_records = [ serialize_doc(mycryptoheroes_record) for mycryptoheroes_record in mycryptoheroes_records ] mycryptoheroes_rec = mycryptoheroes_records[0:1] etheremon_records = mongo.db.etheremon.find({"owner_addresses": address}) etheremon_records = [ serialize_doc(etheremon_record) for etheremon_record in etheremon_records ] etheremon_rec = etheremon_records[0:1] cryptoskulls_records = mongo.db.cryptoskulls.find( {"owner_addresses": address}) cryptoskulls_records = [ serialize_doc(cryptoskulls_record) for cryptoskulls_record in cryptoskulls_records ] cryptoskulls_rec = cryptoskulls_records[0:1] chainbreakers_records = mongo.db.chainbreakers.find( {"owner_addresses": address}) chainbreakers_records = [ serialize_doc(chainbreakers_record) for chainbreakers_record in chainbreakers_records ] chainbreakers_rec = chainbreakers_records[0:1] all_mons = mycryptoheroes_rec + etheremon_rec + cryptoskulls_rec + chainbreakers_rec #+ cryptokitties_records for mons in all_mons: contracts.append(mons) print("4") user_hashrate_sum = [] for all_contracts in contracts: if 'hashrate' in all_contracts: hashrate = all_contracts['hashrate'] user_hashrate_sum.append(hashrate) print("4777777") sum_of_hashrate = sum(user_hashrate_sum) return jsonify({"hashrate": sum_of_hashrate})
def required_message(message_key): if request.method == "GET": ret = mongo.db.mail_template.find({"for": message_key},{"version":0,"version_details":0}) if ret is not None: ret = [template_requirement(serialize_doc(doc)) for doc in ret] return jsonify(ret), 200 else: return jsonify ({"message": "no template exist"}), 200
def local_transaction(address): docs = mongo.db.sws_history.find({"address":address}) docs = [serialize_doc(doc) for doc in docs] return jsonify(docs), 200
def add_user_campaign(): if request.method == "GET": ret = mongo.db.campaign_users.aggregate([]) ret = [campaign_details(serialize_doc(doc)) for doc in ret] return jsonify(ret), 200 if request.method == "POST": users = request.json.get("users") campaign = request.json.get("campaign") for data in users: data['send_status'] = False data['campaign'] = campaign ret = mongo.db.campaign_users.insert_many(users) return jsonify({"message": "Users added to campaign"}), 200
def mycryptoheroes_hashrate_calculation(): print("mycryptoheros_run") records = mongo.db.mycryptoheroes.find({}) records = [serialize_doc(record) for record in records] for record in records: assetId = record['assetId'] total_level = record['total_level'] total_rarity = record['total_rarity'] if 'scarcity_rarity' in record: if 'scarcity_total' in record: scarcity_rarity = record['scarcity_rarity'] scarcity_total = record['scarcity_total'] if total_rarity == "Legendary": rarity = 25 if total_rarity == "Epic": rarity = 15 if total_rarity == "Rare": rarity = 7.5 if total_rarity == "Uncommon": rarity = 5 if total_rarity == "Common": rarity = 2.5 if total_rarity == "Novice": rarity = 0 if total_level > 0 and total_level < 49: level = 0 if total_level > 50 and total_level < 59: level = 15 if total_level > 60 and total_level < 69: level = 17.5 if total_level > 70 and total_level < 79: level = 20 if total_level > 80 and total_level < 89: level = 22.5 if total_level > 90 and total_level < 100: level = 25 hashrate = rarity + level + scarcity_rarity + scarcity_total print(assetId) print(hashrate) ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "hashrate": hashrate }}, upsert=True)
def winner_choose(): print("running") highest = mongo.db.hashrate_calculation.find_one(sort=[("ending_number", -1)]) highest_number = highest['ending_number'] random_number = random.randint(1, int(highest_number)) hashrate_records = mongo.db.hashrate_calculation.find( {"sum_of_hashrate": { "$ne": 0 }}) hashrate_records = [ serialize_doc(hashrate_record) for hashrate_record in hashrate_records ] winner_array = [] print(random_number) for check in hashrate_records: username = check['username'] starting_number = check['starting_number'] ending_number = check['ending_number'] winner_checking = range(starting_number, ending_number) if random_number in winner_checking: winner_array.append(username) else: pass winner = winner_array[0] max_block = mongo.db.winner_block.find_one(sort=[("Block_Number", -1)]) if max_block is not None: block = max_block["Block_Number"] block_number = block + 1 else: block_number = 1 block_insert = mongo.db.winner_block.insert_one({ "Miner": winner, "Block_Number": block_number, "Difficulty": 20, "TimeStamp": datetime.datetime.utcnow(), "Rewards_Type": "CGC", "Reward_Amount": 25 }).inserted_id
def create_campaign(): if request.method == "GET": ret = mongo.db.campaigns.aggregate([]) ret = [Template_details(serialize_doc(doc)) for doc in ret] return jsonify(ret) if request.method == "POST": name = request.json.get("campaign_name", None) description = request.json.get("campaign_description", None) active = request.json.get("active", True) if not name: return jsonify({"msg": "Invalid Request"}), 400 ret = mongo.db.campaigns.insert_one({ "Campaign_name": name, "Campaign_description": description, "active": active, "cron_status": False }).inserted_id return jsonify(str(ret)), 200
def cryptoskulls_hashrate_calculation(): print("crypto run") records = mongo.db.cryptoskulls.find({"name": "cryptoskulls"}, {"assetId": 1}) records = [serialize_doc(record) for record in records] for record in records: assetId = record['assetId'] url = cryptoskull_hashrate_endpoint.replace("{{assets_id}}", '' + assetId + '') response = requests.get(url=url) res = response.json() hashrate = res['hashrate'] print(hashrate) print(assetId) ret = mongo.db.cryptoskulls.update({"assetId": assetId}, {"$set": { "hashrate": hashrate, }}, upsert=True)
def cryptobeasties_hashrate_calculation(): print("cryptobeasties hashrate calculations") records = mongo.db.cryptobeasties.find({}) records = [serialize_doc(record) for record in records] for recor in records: assetId = recor['assetId'] rarity = recor['rarity'] badge = recor['badge'] level_Num = recor['level_Num'] if rarity == "Common": rarity_hash = 5 if rarity == "Uncommon": rarity_hash = 10 if rarity == "Rare": rarity_hash = 15 if rarity == "Epic": rarity_hash = 25 if rarity == "Legendary": rarity_hash = 40 if rarity == "Phenomenal": rarity_hash = 60 if level_Num >= 30: Evolved = True if level_Num < 30: Evolved = False hashrate = rarity_hash print(assetId) ret = mongo.db.cryptobeasties.update({ "assetId":assetId },{ "$set":{ "assetId":assetId, "rarity_hash":rarity_hash, "Evolved":Evolved, "hashrate":hashrate }},upsert=True)
def Ethermon_hashrate_calculation(): print("run") records = mongo.db.etheremon.find({"name": "etheremon"}) records = [serialize_doc(record) for record in records] for record in records: total_level = record['total_level'] catch_index = record['catch_index'] if 'scarcity' in record: scarcity_hashrate = record['scarcity'] assetId = record['assetId'] if total_level < 39: level_hashrate = 0 if total_level > 40 and total_level < 59: level_hashrate = 10 if total_level > 60 and total_level < 79: level_hashrate = 15 if total_level > 80 and total_level < 89: level_hashrate = 20 if total_level > 90 and total_level < 99: level_hashrate = 22.5 if total_level == 100: level_hashrate = 25 if catch_index == 1: catch_hashrate = 25 if catch_index == 2: catch_hashrate = 20 if catch_index == 3: catch_hashrate = 15 else: catch_hashrate = 0 hashrate = level_hashrate + catch_hashrate + scarcity_hashrate print(assetId) ret = mongo.db.etheremon.update({"assetId": assetId}, {"$set": { "hashrate": hashrate }}, upsert=True)
def get_location(): #send these parameters in api radius = request.args.get("radius") latitude = request.args.get("latitude") longitude = request.args.get("longitude") # raising error is any parameters is missing if radius is None: return jsonify({"message" : "Radius in km is required","err":True}), 400 if latitude is None: return jsonify({"message" : "latitude is required","err":True}), 400 if longitude is None: return jsonify({"message" : "longitude is required","err":True}), 400 #create index query used only one time mongo.db.users_location.ensureIndex({"location":"2d"}) # query for find the users from database collection ret = mongo.db.users_location.find({'location': {"$near": [ float(latitude),float(longitude) ],"$maxDistance": float(radius)/111.12 ]}}}) # serializer function for serialize document ret = [serialize_doc(doc) for doc in ret] return jsonify({"users" : ret,"err":False}), 200
def mails_status(): limit = request.args.get('limit', default=0, type=int) skip = request.args.get('skip', default=0, type=int) ret = mongo.db.mail_status.find({}).skip(skip).limit(limit) ret = [serialize_doc(doc) for doc in ret] return jsonify(ret), 200
def Quest_system(): blocks = mongo.db.User_quests.find({}) blocks = [serialize_doc(block) for block in blocks] for block in blocks: print("asdasda")
def list_campaign(): ret = mongo.db.campaigns.aggregate([{"$match": {"active": True}}]) ret = [Template_details(serialize_doc(doc)) for doc in ret] return jsonify(ret), 200
def block_winner(): print("running block") recor = mongo.db.hashrate_calculation.remove() mycursor.execute('SELECT username FROM sws_user') check = mycursor.fetchall() count = 1 for user in check: username = user[0] mycursor.execute( 'SELECT address from sws_address WHERE cms_login_name="' + str(username) + '" ') chek = mycursor.fetchall() contracts = [] for addr in chek: address = addr[0] print("addressssssssssssssssssssssssssss") print(address) heroes_records = mongo.db.participate_heroes.find_one( {"address": address}) chain = heroes_records['chainbreakers'] crypto = heroes_records['cryptoskulls'] ethere = heroes_records['etheremon'] mycrypto = heroes_records['mycryptoheroes'] mycryptoheroes_records = mongo.db.mycryptoheroes.find( {"owner_addresses": address}) mycryptoheroes_records = [ serialize_doc(mycryptoheroes_record) for mycryptoheroes_record in mycryptoheroes_records ] mycryptoheroes_rec = mycryptoheroes_records[0:1] etheremon_records = mongo.db.etheremon.find( {"owner_addresses": address}) etheremon_records = [ serialize_doc(etheremon_record) for etheremon_record in etheremon_records ] etheremon_rec = etheremon_records[0:1] cryptoskulls_records = mongo.db.cryptoskulls.find( {"owner_addresses": address}) cryptoskulls_records = [ serialize_doc(cryptoskulls_record) for cryptoskulls_record in cryptoskulls_records ] cryptoskulls_rec = cryptoskulls_records[0:1] chainbreakers_records = mongo.db.chainbreakers.find( {"owner_addresses": address}) chainbreakers_records = [ serialize_doc(chainbreakers_record) for chainbreakers_record in chainbreakers_records ] chainbreakers_rec = chainbreakers_records[0:1] all_mons = mycryptoheroes_rec + etheremon_rec + cryptoskulls_rec + chainbreakers_rec #+ cryptokitties_records for mons in all_mons: contracts.append(mons) print("4") user_hashrate_sum = [] for all_contracts in contracts: if 'hashrate' in all_contracts: hashrate = all_contracts['hashrate'] user_hashrate_sum.append(hashrate) print("4777777") sum_of_hashrate = sum(user_hashrate_sum) print(len(user_hashrate_sum)) print("499999999") print(sum_of_hashrate) if count == 1: print("5111111111111111111111111") starting_number = 1 ending_number = starting_number + sum_of_hashrate else: print("55555555555555555555555555555555") highest = mongo.db.hashrate_calculation.find_one( sort=[("ending_number", -1)]) print("6000000000000000") print(highest) print("6222222222222222") if highest is not None: starting_number = highest['ending_number'] ending_number = sum_of_hashrate + starting_number print(starting_number) print(ending_number) else: starting_number = None ending_number = None count = count + 1 print("71111111111111") ret = mongo.db.hashrate_calculation.update({"username": username}, { "$set": { "username": username, "sum_of_hashrate": sum_of_hashrate, "starting_number": starting_number, "ending_number": ending_number } }, upsert=True) print("doneeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee")
def mycryptoheroes_scarcity_total_calculation(): print("mycryptoheroes") ''' records = mongo.db.mycryptoheroes.find({}) records = [serialize_doc(record) for record in records] different_description = [] for record in records: print(record) if 'description' in record: description = record['description'] print(description) if description not in different_description: different_description.append(description) count = 1 for descrip in different_description: rets = mongo.db.mycryptoheroes.find({"description":descrip}) rec = [serialize_doc(ret) for ret in rets] for cout in rec: assest = cout['assetId'] print(assest) print(count) ret = mongo.db.mycryptoheroes.update({ "assetId":assest },{ "$set":{ "count":count }},upsert=True) count = count + 1 ''' returnn = mongo.db.mycryptoheroes.find().sort("count", 1) split = [serialize_doc(record) for record in returnn] avg = len(split) / float(10) out = [] last = 0.0 while last < len(split): out.append(split[int(last):int(last + avg)]) last += avg coun = 1 for data in out: for ret in data: assetId = ret['assetId'] if coun == 1: print("111111111111111111111111111111111111") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 0 }}, upsert=False) if coun == 2: print("222222222222222222222222222222") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 2.5 }}, upsert=False) if coun == 3: print("33333333333333333333333333333") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 5 }}, upsert=False) if coun == 4: print("4444444444444444444444444444444") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 7.5 }}, upsert=False) if coun == 5: print("55555555555555555555555555555555") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 10 }}, upsert=False) if coun == 6: print("666666666666666666666666666666") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 15 }}, upsert=False) if coun == 7: print("777777777777777777777777777777777777") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 17.5 }}, upsert=False) if coun == 8: print("8888888888888888888888888888888888888") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 20 }}, upsert=False) if coun == 9: print("99999999999999999999999999999999999999999") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 22.5 }}, upsert=False) if coun == 10: print("100000000000000000000000000000000000000000") ret = mongo.db.mycryptoheroes.update( {"assetId": assetId}, {"$set": { "scarcity_total": 25 }}, upsert=False) coun = coun + 1
def assign_template(campaign_id, template_id): if request.method == "PUT": vac = mongo.db.campaigns.aggregate([ { "$match": { "_id": ObjectId(campaign_id) } }, { "$project": { "status": { "$cond": { "if": { "$ifNull": ["$Template", False] }, "then": { "state": { "$in": [template_id, "$Template"] } }, "else": { "state": False } } } } }, ]) for data in vac: print(data['status']) if data['status'] is not None and data['status']['state'] is False: ret = mongo.db.campaigns.update( {"_id": ObjectId(campaign_id)}, {"$push": { "Template": template_id }}) return jsonify({"message": "Template added to campaign"}), 200 else: return jsonify({"message": "Template exist in campaign"}), 200 if request.method == "DELETE": vac = mongo.db.campaigns.aggregate([ { "$match": { "_id": ObjectId(campaign_id) } }, { "$project": { "status": { "$in": [template_id, "$Template"] }, "count": { "$cond": { "if": { "$isArray": "$Template" }, "then": { "$size": "$Template" }, "else": "NULL" } } } }, ]) vac = [serialize_doc(doc) for doc in vac] for data in vac: if data['status'] is True: if data['count'] >= 1: ret = mongo.db.campaigns.update( {"_id": ObjectId(campaign_id)}, {"$pull": { "Template": template_id }}) return jsonify( {"message": "Template removed from campaign"}), 200 else: return jsonify({ "message": "Template for the campaign cannot be none" }), 400 else: return jsonify( {"message": "Template does not exist in this campaign"}), 400
def mail_setings(origin, id=None): if request.method == "GET": mail = mongo.db.mail_settings.find({"origin": origin}, {"mail_password": 0}) mail = [serialize_doc(doc) for doc in mail] return jsonify(mail) if request.method == "DELETE": mail = mongo.db.mail_settings.remove({ "origin": origin, "_id": ObjectId(str(id)) }) return jsonify({"message": "Smtp conf deleted"}), 200 if request.method == "PUT": ret = mongo.db.mail_settings.update({ "origin": origin, "active": True }, {"$set": { "active": False }}, multi=True) mail = mongo.db.mail_settings.update( { "origin": origin, "_id": ObjectId(str(id)) }, {"$set": { "active": True }}) return jsonify({"message": "Smtp conf set as active"}), 200 if request.method == "POST": if not request.json: abort(500) mail_server = request.json.get("mail_server", "smtp.gmail.com") mail_port = request.json.get("mail_port", 465) mail_use_tls = request.json.get("mail_use_tls", True) mail_username = request.json.get("mail_username", None) mail_password = request.json.get("mail_password", None) mail_from = request.json.get("mail_from", None) active = request.json.get("active", True) type_s = request.json.get("type", "tls") if not mail_server and mail_password and mail_port and mail_use_tls and mail_username: return jsonify({"message": "Invalid Request"}), 400 email = None if mail_from is None: email = mail_username else: email = mail_from try: send_email(message="SMTP WORKING!", recipients=[email], subject="SMTP TESTING MAIL!", sending_mail=mail_username, sending_password=mail_password, sending_port=mail_port, sending_server=mail_server) except smtplib.SMTPServerDisconnected: return jsonify({"message": "Smtp server is disconnected"}), 400 except smtplib.SMTPConnectError: return jsonify({"message": "Smtp is unable to established"}), 400 except smtplib.SMTPAuthenticationError: return jsonify({"message": "Smtp login and password is wrong"}), 400 except smtplib.SMTPDataError: return jsonify({"message": "Smtp account is not activated"}), 400 except Exception as e: print(repr(e), "EXCEPTION") return jsonify({"message": repr(e)}), 400 else: if origin == "HR": ret = mongo.db.mail_settings.update({}, { "$set": { "mail_server": mail_server, "mail_port": mail_port, "origin": origin, "mail_use_tls": mail_use_tls, "mail_username": mail_username, "mail_password": mail_password, "mail_from": mail_from } }, upsert=True) return jsonify({"message": "upsert"}), 200 elif origin == "RECRUIT": vet = mongo.db.mail_settings.find_one({ "mail_username": mail_username, "mail_password": mail_password, "origin": origin }) if vet is None: exist = mongo.db.mail_settings.find_one({"origin": origin}) if exist is None: active = True else: active = False ret = mongo.db.mail_settings.insert_one({ "mail_server": mail_server, "mail_port": mail_port, "origin": origin, "mail_use_tls": mail_use_tls, "mail_username": mail_username, "mail_password": mail_password, "active": active, "type": type_s, "mail_from": mail_from }) return jsonify({"message": "upsert"}), 200 else: return jsonify({"message": "Smtp already exists"}), 400
def send_mails(): if not request.json: abort(500) for elem in dates_converter: if elem in request.json['data']: if request.json['data'][elem] is not None: if request.json['data'][elem] != "": if request.json['data'][elem] != "No Access": date_formatted = dateutil.parser.parse(request.json['data'][elem]).strftime("%d %b %Y") request.json['data'][elem] = date_formatted MSG_KEY = request.json.get("message_key", None) Data = request.json.get("data",None) Message = request.json.get("message",None) Subject = request.json.get("subject",None) message_detail = mongo.db.mail_template.find_one({"message_key": MSG_KEY}) if message_detail is not None: if Message is not None: message_detail['message'] = Message else: pass if Subject is not None: if Subject != "": message_detail['message_subject'] = Subject else: pass attachment_file = None attachment_file_name = None if 'attachment' in request.json: if 'attachment_file' in message_detail: attachment_file = message_detail['attachment_file'] if 'attachment_file_name' in message_detail: attachment_file_name = message_detail['attachment_file_name'] else: pass files = None if 'attachment_files' in message_detail: if message_detail['attachment_files']: files = message_detail['attachment_files'] header = None footer = None if 'template_head' in message_detail: var = mongo.db.letter_heads.find_one({"_id":ObjectId(message_detail['template_head'])}) if var is not None: header = var['header_value'] footer = var['footer_value'] system_variable = mongo.db.mail_variables.find({}) system_variable = [serialize_doc(doc) for doc in system_variable] missing_payload = [] message_variables = [] message = message_detail['message'].split('#') del message[0] rex = re.compile('!|@|\$|\%|\^|\&|\*|\:') for elem in message: varb = re.split(rex, elem) message_variables.append(varb[0]) message_str = message_detail['message'] for detail in message_variables: if detail in request.json['data']: if request.json['data'][detail] is not None: rexWithString = '#' + re.escape(detail) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:])' message_str = re.sub(rexWithString, str(request.json['data'][detail]), message_str) else: for element in system_variable: if "#" + detail == element['name'] and element['value'] is not None: rexWithSystem = re.escape(element['name']) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:])' message_str = re.sub(rexWithSystem, str(element['value']), message_str) missing = message_str.split('#') del missing[0] missing_rex = re.compile('!|@|\$|\%|\^|\&|\*|\:') for elem in missing: missing_data = re.split(missing_rex, elem) missing_payload.append({"key": missing_data[0] , "type": "date" if missing_data[0] in dates_converter else "text"}) subject_variables = [] message_sub = message_detail['message_subject'].split('#') del message_sub[0] regex = re.compile('!|@|\$|\%|\^|\&|\*|\:') for elem in message_sub: sub_varb = re.split(regex, elem) subject_variables.append(sub_varb[0]) message_subject = message_detail['message_subject'] for detail in subject_variables: if detail in request.json['data']: if request.json['data'][detail] is not None: rexWithString = '#' + re.escape(detail) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:])' message_subject = re.sub(rexWithString, str(request.json['data'][detail]), message_subject) else: for element in system_variable: if "#" + detail == element['name'] and element['value'] is not None: rexWithSystem = re.escape(element['name']) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:])' message_subject = re.sub(rexWithSystem, str(element['value']), message_subject) missing_subject = message_subject.split("#") del missing_subject[0] missing_sub_rex = re.compile('!|@|\$|\%|\^|\&|\*|\:') for elem in missing_subject: sub_varb_missing = re.split(missing_sub_rex, elem) missing_payload.append({"key": sub_varb_missing[0] , "type": "date" if sub_varb_missing[0] in dates_converter else "text"}) if 'fromDate' in request.json['data'] and request.json['data']['fromDate'] is not None: if 'toDate' in request.json['data'] and request.json['data']['toDate'] is not None: if request.json['data']['fromDate'] == request.json['data']['toDate']: message_str = message_str.replace(request.json['data']['fromDate'] + " to " + request.json['data']['toDate'],request.json['data']['fromDate']) if 'fromDate' in request.json['data'] and request.json['data']['fromDate'] is not None: if 'toDate' in request.json['data'] and request.json['data']['toDate'] is not None: if request.json['data']['fromDate'] == request.json['data']['toDate']: message_subject = message_subject.replace(request.json['data']['fromDate'] + " to " + request.json['data']['toDate'],request.json['data']['fromDate']) download_pdf = "#letter_head #content #letter_foot" if header is not None: download_pdf = download_pdf.replace("#letter_head",header) else: download_pdf = download_pdf.replace("#letter_head",'') download_pdf = download_pdf.replace("#content",message_str) if footer is not None: download_pdf = download_pdf.replace("#letter_foot",footer) else: download_pdf = download_pdf.replace("#letter_foot",'') if message_detail['message_key'] == "Payslip": system_settings = mongo.db.system_settings.find_one({},{"_id":0}) if system_settings is not None: if system_settings['pdf'] is True: filename = "{}.pdf".format(str(uuid.uuid4())) pdfkit = HTML(string=message_str).write_pdf(os.getcwd() + '/attached_documents/' + filename,stylesheets=[CSS(string='@page {size:Letter; margin: 0in 0in 0in 0in;}')]) attachment_file_name = filename attachment_file = os.getcwd() + '/attached_documents/' + filename else: pass to = None bcc = None cc = None if app.config['ENV'] == 'development': if 'to' in request.json: to = [app.config['to']] bcc = [app.config['bcc']] cc = [app.config['cc']] else: pass else: if app.config['ENV'] == 'production': if 'to' in request.json: if not request.json['to']: to = None else: to = request.json['to'] else: to = None if 'bcc' in request.json: if not request.json['bcc']: bcc = None else: bcc = request.json['bcc'] else: bcc = None if 'cc' in request.json: if not request.json['cc']: cc = None else: cc = request.json['cc'] else: cc = None if message_detail['message_key'] == "interviewee_reject": reject_mail = None if app.config['ENV'] == 'production': if 'email' in request.json['data']: reject_mail = request.json['data']['email'] else: return jsonify({"status": False,"Message": "No rejection mail is sended"}), 400 else: if app.config['ENV'] == 'development': reject_mail = [app.config['to']] reject_handling = mongo.db.rejection_handling.insert_one({ "email": request.json['data']['email'], 'rejection_time': request.json['data']['rejection_time'], 'send_status': False, 'message': message_str, 'subject': message_subject }).inserted_id return jsonify({"status":True,"*Note":"Added for Rejection"}),200 else: if to is not None: send_email(message=message_str,recipients=to,subject=message_subject,bcc=bcc,cc=cc,filelink=attachment_file,filename=attachment_file_name,files=files) return jsonify({"status":True,"Subject":message_subject,"Message":download_pdf,"attachment_file_name":attachment_file_name,"attachment_file":attachment_file,"missing_payload":missing_payload}),200 else: return jsonify({"status":True,"*Note":"No mail will be sended!","Subject":message_subject,"Message":download_pdf,"attachment_file_name":attachment_file_name,"attachment_file":attachment_file,"missing_payload":missing_payload}),200
def Ethermon_scarcity_calculation(): class_names = mon_names uncommon_scarity = [ "Wolverize", "Siberizen", "Tekagon", "Quadrossal", "Vernirox", "Zedakazm", "Baulder", "Barkindle", "Ruffski" ] for class_name in class_names: if class_name in uncommon_scarity: records = mongo.db.etheremon.find({"class_name": class_name}) records = [serialize_doc(record) for record in records] for recor in records: classs = recor['class_name'] assetId = recor['assetId'] ret = mongo.db.etheremon.update({"assetId": assetId}, {"$set": { "scarcity": 25 }}, upsert=False) else: common_scarity = [ "Pangrove", "Darcastro", "Wrecktile", "Primasham", "Reefallion", "Noxibeet", "Chromothic", "Capareef", "Expertri", "Duscre", "Monstratos", "Resurvy", "Liscious", "Aromerita", "Aphroxid", "Dehedra", "Raxplode", "Dillossus", "Qairrel" ] records = mongo.db.etheremon.find({"class_name": class_name}) records = [serialize_doc(record) for record in records] avg = len(records) / float(10) out = [] last = 0.0 while last < len(records): out.append(records[int(last):int(last + avg)]) last += avg count = 1 for data in out: for ret in data: assetId = ret['assetId'] classs = ret['class_name'] if count == 1: print("111111111111111111111111111111111111") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 1 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 1 }}, upsert=False) if count == 2: print("222222222222222222222222222222") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 2 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 2 }}, upsert=False) if count == 3: print("33333333333333333333333333333") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 3 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 3 }}, upsert=False) if count == 4: print("4444444444444444444444444444444") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 4 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 4 }}, upsert=False) if count == 5: print("55555555555555555555555555555555") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 5 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 5 }}, upsert=False) if count == 6: print("666666666666666666666666666666") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 6 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 6 }}, upsert=False) if count == 7: print("777777777777777777777777777777777777") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 7 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 7 }}, upsert=False) if count == 8: print("8888888888888888888888888888888888888") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 8 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 8 }}, upsert=False) if count == 9: print("99999999999999999999999999999999999999999") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 9 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 9 }}, upsert=False) if count == 10: print("100000000000000000000000000000000000000000") if classs in common_scarity: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 10 + 10 }}, upsert=False) else: ret = mongo.db.etheremon.update( {"assetId": assetId}, {"$set": { "scarcity": 10 }}, upsert=False) count = count + 1
def invoice_notification(): print("asdasndas,na") dab = mongo.db.sws_pending_txs_from_app.find({"type": "invoice"}) dab = [serialize_doc(doc) for doc in dab] for data in dab: frm = data['from'] to = data['to'] symbol = data['symbol'] amount = data['amt'] notes = data['from_notes'] to_username = data['to_username'] print("from") print(frm) print("to") print(to) print(amount) dabb = mongo.db.sws_history.find( { "transactions": { '$elemMatch': { "from": { '$elemMatch': { "from": to, "send_amount": amount } }, "to": { '$elemMatch': { "to": frm } } } } }, {"transactions.$": 1}) dabb = [serialize_doc(doc) for doc in dabb] print(dabb) if dabb: for data in dabb: trans = data['transactions'] for tx_id in trans: transaction_id = tx_id['Tx_id'] docs = mongo.db.sws_pending_txs_from_app.remove({ "from": frm, "to": to, "amt": amount, "type": "invoice" }) report = mongo.db.sws_notes.insert_one({ "tx_id": transaction_id, "notes": notes, "from": frm, "to": to, "type": "invoice", "username": to_username, "update_at": datetime.datetime.now(), "created_at": datetime.datetime.now() }).inserted_id else: mycursor.execute( 'SELECT u.email FROM db_safename.sws_address as a left join db_safename.sws_user as u on a.cms_login_name = u.username where a.address="' + str(to) + '"') email = mycursor.fetchone() print(email) if email is not None: email_id = email[0] print(email_id) message = Mail( from_email=Sendgrid_default_mail, to_emails='*****@*****.**', subject='SafeName - Invoice Notification In Your Account', html_content= '<h3> Your invoice is not clear please accept the request</h3>' ) sg = SendGridAPIClient(SendGridAPIClient_key) response = sg.send(message) print(response.status_code, response.body, response.headers)
def cryptokitties_hashrate_calculation(): print("assdajadja") fancyness = [ "BugCat", "Lilbubthemagicspacecat", "RabbidKitty", "KnightKitty", "DracoTheMagnificent", "BugCatV2", "SirMeowsalot", "旺财汪", "Furlin" ] comon = ["Hinecatone", "Vulcant", "Felono", "DAPP-E"] Rare = ["Catbury", "Catzy", "PurremyAllaire"] assest = [1, 127, 251, 269, 282, 402, 500000, 1000000, 1500000] asses = [2, 100] records = mongo.db.cryptokitties.find({}) records = [serialize_doc(record) for record in records] for record in records: assetId = record['assetId'] fancy_ranking = record['fancy_ranking'] fanciness = record['fanciness'] if assetId in assest: Unique_Exclusives = 0 else: Unique_Exclusives = 0 if assetId in asses: Founders = 0 else: Founders = 0 if fancy_ranking == 1: Fancies = 0 else: Fancies = 0 if fanciness in fancyness: Rare_Exclusives = 0 else: Rare_Exclusives = 0 if fanciness == "Schrödingerscat": Schrödingerscat = 0 else: Schrödingerscat = 0 if fanciness in comon: Common_exclusives = 0 else: Common_exclusives = 0 if fanciness in Rare: Rare_fancies = 0 else: Rare_fancies = 0 hashrate = Unique_Exclusives + Founders + Fancies + Rare_Exclusives + Schrödingerscat + Common_exclusives + Rare_fancies print(assetId) ret = mongo.db.cryptokitties.update({"assetId": assetId}, { "$set": { "assetId": assetId, "Unique_Exclusives": Unique_Exclusives, "Founders": Founders, "Fancies": Fancies, "Rare_Exclusives": Rare_Exclusives, "Schrödingerscat": Schrödingerscat, "Common_exclusives": Common_exclusives, "Rare_fancies": Rare_fancies, "hashrate": hashrate } }, upsert=True)
def auto_fetch(): print('running...') records = mongo.db.address.find({}) records = [serialize_doc(doc) for doc in records] for record in records: records = mongo.db.symbol_url.find_one({"symbol": symbol}) url = records['url_balance'] if "url_trans" in records: url1 = records['url_trans'] ret = url.replace("{{address}}", '' + address + '') ret1 = ret.replace("{{symbol}}", '' + symbol + '') address = record['address'] symbol = record['symbol'] response_user_token = requests.get(url=ret1) response = response_user_token.json() if symbol == "BTC" or "LTC": transaction = response['data'] balance = transaction['balance'] amountReceived = transaction['amountReceived'] amountSent = transaction['amountSent'] transactions = transaction['txs'] array = [] for transaction in transactions: fee = transaction['fee'] to = transaction['outputs'][0]['address'] timestamp = transaction['timestamp'] dt_object = datetime.fromtimestamp(timestamp) array.append({ "fee": fee, "from": address, "to": to, "date": dt_object }) if symbol == "ETH": transaction = response['data'] balance = transaction['balance'] amountReceived = transaction['amountReceived'] amountSent = transaction['amountSent'] transactions = transaction['txs'] array = [] for transaction in transactions: to = transaction['to'] frm = transaction['from'] price = transaction['quote']['price'] timestamp = transaction['timestamp'] dt_object = datetime.fromtimestamp(timestamp) array.append({ "from": frm, "to": to, "date": dt_object, "fee": price }) ret = mongo.db.address.update( {"address": address}, {"$set": { "address": address, "symbol": symbol }}, upsert=True) ret = mongo.db.address.find_one({"address": address}) _id = ret['_id'] ret = mongo.db.balance.update({"address": address}, { "$set": { "record_id": str(_id), "address": address, "symbol": symbol, "balance": balance, "amountReceived": amountReceived, "amountSent": amountSent } }, upsert=True) ret = mongo.db.transactions.update({"address": address}, { "$set": { "record_id": str(_id), "address": address, "transactions": array, "symbol": symbol } }, upsert=True)
def currency_symbol(): urls = mongo.db.symbol_url.find({}) urls = [serialize_doc(doc) for doc in urls] return jsonify(urls), 200
def campaign_mail(): ret = mongo.db.campaign_users.find_one({"send_status":False}) if ret is not None: if app.config['ENVIRONMENT'] == "development": mail = "*****@*****.**" else: mail = ret['email'] cam = mongo.db.campaigns.find_one({"_id":ObjectId(ret['campaign'])}) if cam is not None: if 'Template' in cam: for data in cam['Template']: system_variable = mongo.db.mail_variables.find({}) system_variable = [serialize_doc(doc) for doc in system_variable] temp = mongo.db.mail_template.find_one({"_id":ObjectId(data)}) subject = temp['message_subject'] message_variables = [] message = temp['message'].split('#') del message[0] rex = re.compile('!|@|\$|\%|\^|\&|\*|\:|\;') for elem in message: varb = re.split(rex, elem) message_variables.append(varb[0]) message_str = temp['message'] for detail in message_variables: if detail in ret: rexWithString = '#' + re.escape(detail) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:]|[\;])' message_str = re.sub(rexWithString, ret[detail], message_str) else: for element in system_variable: if "#" + detail == element['name'] and element['value'] is not None: rexWithSystem = re.escape(element['name']) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:]|[\;])' message_str = re.sub(rexWithSystem, element['value'], message_str) subject_variables = [] message_sub = subject.split('#') del message_sub[0] regex = re.compile('!|@|\$|\%|\^|\&|\*|\:|\;') for elem in message_sub: sub_varb = re.split(regex, elem) subject_variables.append(sub_varb[0]) message_subject = subject for detail in subject_variables: if detail in ret: rexWithString = '#' + re.escape(detail) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:]|[\;])' message_subject = re.sub(rexWithString, ret[detail], message_subject) else: for element in system_variable: if "#" + detail == element['name'] and element['value'] is not None: rexWithSystem = re.escape(element['name']) + r'([!]|[@]|[\$]|[\%]|[\^]|[\&]|[\*]|[\:]|[\;])' message_subject = re.sub(rexWithSystem, element['value'], message_subject) to = [] to.append(mail) working_status = True try: send_email(message=message_str,recipients=to,subject=subject) except Exception: working_status = False mail_data = mongo.db.mail_status.insert_one({ "user_mail": ret['email'], "user_id": str(ret['_id']), "sending_time": datetime.datetime.now(), "message": message_str, "mail_sended_status": working_status, "subject":subject, "recipients": to }) campaign = mongo.db.campaigns.update({"_id":ObjectId(ret['campaign'])}, { "$set": { "cron_status": True } }) user_status = mongo.db.campaign_users.update({"_id":ObjectId(ret['_id'])}, { "$set": { "send_status": True } }) else: pass else: pass else: pass
def chainbreakers_hashrate_calculation(): print("run") records = mongo.db.chainbreakers.find({}, {"assetId": 1}) records = [serialize_doc(record) for record in records] print(records) for record in records: assetId = record['assetId'] url = chainbreakers_armor_endpoint.replace("{{assets_id}}", '' + assetId + '') print(url) response = requests.get(url=url) res = response.json() traits = res['traits'] count = 0 for trait in traits: if trait["trait_type"] == "protection": print( "protectionnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn" ) protection = trait["trait_type"] count = count + 1 print(count) print("assetId") print(assetId) if count >= 1: print("adaskdsandaskdjasd") for trait in traits: if trait["trait_type"] == "generation": generation_value = trait["value"] if trait["trait_type"] == "mint_number": mint_number = trait["value"] genration_hashrate = 0 if generation_value == 1: genration_hashrate = 30 if generation_value == 2: genration_hashrate = 27.5 mint_number_hashrate = 0 if mint_number == 1: mint_number_hashrate = 20 if mint_number == 2: mint_number_hashrate = 15 if mint_number == 3: mint_number_hashrate = 10 if mint_number > 4: mint_number_hashrate = 0 hashrate = genration_hashrate + mint_number_hashrate print(hashrate) ret = mongo.db.chainbreakers.update({"assetId": assetId}, { "$set": { "generation": generation_value, "mint_number": mint_number, "hashrate": hashrate, "armor_type": "armor" } }, upsert=True) else: print("elseeeeeee") for trait in traits: if trait["trait_type"] == "generation": generation_value = trait["value"] if trait["trait_type"] == "rarity": rarity_class = trait["value"] if trait["trait_type"] == "mint_number": mint_number = trait["value"] genration_hashrate = 0 if generation_value == 0: genration_hashrate = 5 if generation_value == 1: genration_hashrate = 2.5 if generation_value == 2: genration_hashrate = 0 rarity_hashrate = 0 if rarity_class == "epic": rarity_hashrate = 30 if rarity_class == "rare": rarity_hashrate = 7.5 if rarity_class == "uncommon": rarity_hashrate = 5 if rarity_class == "common": rarity_hashrate = 2.5 mint_number_hashrate = 0 if rarity_class == "epic" and mint_number == 1: mint_number_hashrate = 20 if rarity_class == "epic" and mint_number == 2: mint_number_hashrate = 15 if rarity_class == "epic" and mint_number == 3: mint_number_hashrate = 10 if rarity_class == "rare" and mint_number == 1: mint_number_hashrate = 10 if rarity_class == "rare" and mint_number == 2: mint_number_hashrate = 7.5 if rarity_class == "rare" and mint_number == 3: mint_number_hashrate = 5 if rarity_class == "uncommon" and mint_number == 1: mint_number_hashrate = 7.5 if rarity_class == "uncommon" and mint_number == 2: mint_number_hashrate = 5 if rarity_class == "uncommon" and mint_number == 3: mint_number_hashrate = 5 if rarity_class == "common" and mint_number == 1: mint_number_hashrate = 5 if rarity_class == "common" and mint_number == 2: mint_number_hashrate = 2.5 if rarity_class == "common" and mint_number == 3: mint_number_hashrate = 2.5 hashrate = genration_hashrate + rarity_hashrate + mint_number_hashrate print(hashrate) ret = mongo.db.chainbreakers.update({"assetId": assetId}, { "$set": { "generation": generation_value, "rarity_class": rarity_class, "mint_number": mint_number, "armor_type": "weapons", "hashrate": hashrate } }, upsert=True)