class Tasks(object): def __init__(self): self._db_hlp = DbHelper() self._cmd_list = self._get_cmd_list() def _first_run(self): #print birthday dates return self._db_hlp.check_birthdays() def _get_cmd_list(self): res="available commands: \r\n" for i in dir(self): if not i.startswith('_'): res += "- "+i +"\r\n" return res[:-2] def add_record(self): user_input = raw_input(Messages.add_record) user_input = self.__check_input(user_input) def show_all(self): for i in self._db_hlp.select_all(): print i def exit(self): sys.exit(0)
def get_payments(): database = DbHelper() columns = [c[0] for c in database.get_payments_discounts_columns()] return jsonify({ 'payments': [dict(zip(columns, t)) for t in database.get_payments_from_database()] })
def refresh_database(bunq, user): discounts = user['discounts'] database = DbHelper() existing_tx = [tranx[0] for tranx in database.get_payments_from_database()] #### FIRST TIME DATABASE INITIALIZATION ###### history = bunq.get_all_payment(count=200) # for h in history: # if h.description.split("-")[0] != "CASHBACK": # _, dsc = determine_discount(h.description, user) # database.add_payment_to_database(h.id_, h.description, h.amount.value, dsc*h.amount.value) # existing_tx.append(h.id_) while True: new_payments = bunq.get_all_payment(5) for npy in new_payments: if str(npy.id_) not in existing_tx and npy.description.split( "-")[0] != "CASHBACK": # Check discount eligibility shop, dsc = determine_discount(npy.description, user) existing_tx.append(str(npy.id_)) # Add new payment to database database.add_payment_to_database(npy.id_, npy.description, npy.amount.value, dsc * float(npy.amount.value)) if shop is not None: # Request cashback from sugar daddy desc = "{}-{}-{}".format("CASHBACK", shop, dsc) bunq.make_request(dsc, desc, "*****@*****.**") # Increase the points the shopper has for i, discount in enumerate(discounts): print(i, discount) if discount['shop'] == shop: level_before = get_level(discounts[i]) user['discounts'][i]['current_points'] += int( dsc * -1 * float(npy.amount.value)) * 10 level_after = get_level(discounts[i]) if level_before != level_after: user['loots']['number'] += 1 socketio.emit( 'NewPayment', { 'shop': { 'name': shop, 'current_points': user['discounts'][i]['current_points'], 'loot_number': user['loots']['number'] } }) time.sleep(3)
def render_GET(self, request): gi = pygeoip.GeoIP('GeoIP.dat', pygeoip.MEMORY_CACHE) country_code = gi.country_code_by_addr(request.getHeader('x-forwarded-for')) macdb = DbHelper() res = macdb.uncensorp_fetch_by_iso(country_code) res = { 'domains': [rec['domain'] for rec in res], 'country_code': country_code, 'country_name': pycountry.countries.get(alpha2=country_code).name.encode('utf-8') } macdb.cleanup() request.setHeader('Content-Type', 'application/json') return json.dumps(res)
def render_POST(self, request): macdb = DbHelper() if not 'action' in request.args: request.setResponseCode(400) return 'Error 400. Bad request.' output = "" if request.args['action'][0] == 'delete': id_ = int(request.args['id'][0]) rec = macdb.uncensorp_fetch_by_id(id_) request.setResponseCode(301) if rec != None: macdb.uncensorp_delete(id_) request.setHeader('Location', self.pathFromRoot + '?msg=' + urllib.quote_plus('Success. Record deleted.')) else: request.setHeader('Location', self.pathFromRoot + '?msg=' + urllib.quote_plus('Error. Record not found.')) elif request.args['action'][0] == 'add': if (not ('domain' in request.args)) or (not ('iso' in request.args)): request.setResponseCode(400) return 'Error 400. Bad request.' insertInfo = { 'domain': request.args['domain'][0], 'iso': request.args['iso'][0] } macdb.uncensorp_insert(insertInfo) request.setResponseCode(301) request.setHeader('Location', self.pathFromRoot + '?msg=' + urllib.quote_plus('Success. Record was added.')) else: request.setResponseCode(400) output = 'Error 400. Bad request.' macdb.cleanup() return output
def main(): all_option = ShareLib.parse_all_option() environment_type = ShareLib.determine_environment_type_from_all_option( all_option) ShareLib.print_header() bunq = BunqLib(environment_type) user = bunq.get_current_user() user_discounts = UserDiscounts() discounts = user_discounts.get_discounts() database = DbHelper() Thread(target=refresh_database, args=(bunq, discounts)).start() # all_request = bunq.get_all_request(1) # ShareLib.print_all_request(all_request) # # all_card = bunq.get_all_card(1) # ShareLib.print_all_card(all_card, all_monetary_account_bank_active) # # if environment_type is ApiEnvironmentType.SANDBOX: # all_alias = bunq.get_all_user_alias() # ShareLib.print_all_user_alias(all_alias) # # bunq.update_context() socketio.run(app, debug=True, port=5000)
def render_GET(self, request): macdb = DbHelper() ua = request.requestHeaders.getRawHeaders('User-Agent') if ua != None: ua = ua[0] matchObj = re.match(r'.*? (\(.*?\)) .*', ua) os = None version = None if matchObj: x2 = matchObj.group(1) os = 'win' if (x2.find('Windows') != -1) else 'mac' if ( x2.find('Mac OS') != -1) else None matchObj = re.match(r'.* BitPop/(\d+\.\d+\.\d+\.\d+) .*', ua) # get version if matchObj: version = matchObj.group(1) if version and os: macdb.stats_add(version, os) res = macdb.uncensor_fetch_all() macdb.cleanup() request.setHeader('Content-Type', 'application/json') return json.dumps(res)
def render_GET(self, request): macdb = DbHelper() ua = request.requestHeaders.getRawHeaders('User-Agent') if ua != None: ua = ua[0] matchObj = re.match( r'.*? (\(.*?\)) .*', ua) os = None version = None if matchObj: x2 = matchObj.group(1) os = 'win' if (x2.find('Windows') != -1) else 'mac' if (x2.find('Mac OS') != -1) else None matchObj = re.match( r'.* BitPop/(\d+\.\d+\.\d+\.\d+) .*', ua) # get version if matchObj: version = matchObj.group(1) if version and os: macdb.stats_add(version, os) res = macdb.uncensor_fetch_all() macdb.cleanup() request.setHeader('Content-Type', 'application/json') return json.dumps(res)
def render_GET(self, request): request.setHeader('Content-Type', 'application/rss+xml') macdb = DbHelper() items = macdb.fetch_several_latest(5) output = """<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <title>BitPop Update Feed</title> <link>""" output += Config.insecureDomain + self.pathFromRoot output += """</link> <description>List of BitPop packages with different versions.</description> <language>en</language>""" if len(items) > 0: for item in items: output += """ <item> <title>Version {0}</title> <description><![CDATA[ {1} ]]></description> <pubDate>{2}</pubDate> <enclosure url="{3}" sparkle:version="{0}" length="{4}" type="application/octet-stream" sparkle:dsaSignature="{5}" /> </item>""".format( item['version'], item['rel_notes'], strftime( "%a, %d %b %Y %H:%M:%S +0000", datetime.utcfromtimestamp(item['pub_ts']).timetuple()), getUpdateURLMac('BitPop-' + item['version'] + '.dmg'), item['dmg_size'], item['dsa_signature']) output += """ </channel> </rss> """ macdb.cleanup() return output
def render_POST(self, request): macdb = DbHelper() if not 'action' in request.args: request.setResponseCode(400) return 'Error 400. Bad request.' output = "" if request.args['action'][0] == 'delete': id_ = int(request.args['id'][0]) rec = macdb.uncensor_fetch_by_id(id_) request.setResponseCode(301) if rec != None: macdb.uncensor_delete(id_) request.setHeader( 'Location', self.pathFromRoot + '?msg=' + urllib.quote_plus('Success. Record deleted.')) else: request.setHeader( 'Location', self.pathFromRoot + '?msg=' + urllib.quote_plus('Error. Record not found.')) elif request.args['action'][0] == 'add': if (not ('srcDomain' in request.args)) or (not ('dstDomain' in request.args)): request.setResponseCode(400) return 'Error 400. Bad request.' insertInfo = { 'srcDomain': request.args['srcDomain'][0], 'dstDomain': request.args['dstDomain'][0] } macdb.uncensor_insert(insertInfo) request.setResponseCode(301) request.setHeader( 'Location', self.pathFromRoot + '?msg=' + urllib.quote_plus('Success. Record was added.')) else: request.setResponseCode(400) output = 'Error 400. Bad request.' macdb.cleanup() return output
def render_GET(self, request): request.setHeader('Content-Type', 'application/rss+xml') macdb = DbHelper() items = macdb.fetch_several_latest(5) output = """<?xml version="1.0" encoding="utf-8"?> <rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <title>BitPop Update Feed</title> <link>""" output += Config.insecureDomain + self.pathFromRoot output += """</link> <description>List of BitPop packages with different versions.</description> <language>en</language>""" if len(items) > 0: for item in items: output += """ <item> <title>Version {0}</title> <description><![CDATA[ {1} ]]></description> <pubDate>{2}</pubDate> <enclosure url="{3}" sparkle:version="{0}" length="{4}" type="application/octet-stream" sparkle:dsaSignature="{5}" /> </item>""".format(item['version'], item['rel_notes'], strftime("%a, %d %b %Y %H:%M:%S +0000", datetime.utcfromtimestamp(item['pub_ts']).timetuple()), getUpdateURLMac('BitPop-' + item['version'] + '.dmg'), item['dmg_size'], item['dsa_signature']) output += """ </channel> </rss> """ macdb.cleanup() return output
def render_GET(self, request): tr = re.compile('.*/(\d*)$') m = re.match(tr, request.path) if len(m.groups()) == 0: request.setResponseCode(400) # Bad request return "Error: Bad request." update_id = m.groups()[0] macdb = DbHelper() upd = macdb.fetch_by_id(int(update_id)) if upd == None: request.setResponseCode(404) # Bad request return "Error: Not found." macdb.delete(int(update_id)) try: activeStream = open(Config.macActiveVersionFile, 'r') try: vt = activeStream.readline().strip(' \t\n\r') finally: activeStream.close() if vt == upd['version']: newLatest = macdb.fetch_latest() if newLatest == None: #delete file os.remove(Config.macActiveVersionFile) else: activeStream = open(Config.macActiveVersionFile, 'w') try: activeStream.write(newLatest['version'] + '\n') finally: activeStream.close() except IOError: pass macdb.cleanup() return """<!DOCTYPE html>
def render_POST(self, request): if not 'rel_notes' in request.args or not 'rec_id' in request.args: request.setResponseCode(400) # Bad request return "Error: Bad request." macdb = DbHelper() upd = macdb.fetch_by_id(int(request.args['rec_id'][0])) if upd == None: request.setResponseCode(404) # Bad request return "Error: Not found." upd['rel_notes'] = request.args['rel_notes'][0] macdb.update(upd) macdb.cleanup() return """<!DOCTYPE html>
def render_POST(self, request): if not 'rel_notes' in request.args or not 'rec_id' in request.args: request.setResponseCode(400) # Bad request return "Error: Bad request." macdb = DbHelper() upd = macdb.fetch_by_id(int(request.args['rec_id'][0])) if upd == None: request.setResponseCode(404) # Bad request return "Error: Not found." upd['rel_notes'] = request.args['rel_notes'][0]; macdb.update(upd) macdb.cleanup() return """<!DOCTYPE html>
params = {'mode': mode, 'season': season, 'category': category} # url = 'https://api.xiaoheihe.cn/game/pubg/get_player_leaderboards/?lang=zh-cn&os_type=iOS&os_version=10.3.3&version=1.1.52&device_id=D2AA4D4F-AC80-476C-BFE1-CBD83AB74133&heybox_id=5141514&limit=30&offset=0&mode=solo&season=pc-2018-02&category=WinRatio' # 上面为抓包拿到的url,经过测试,其他参数可省略,只需下面的url即可 url = 'https://api.xiaoheihe.cn/game/pubg/get_player_leaderboards/' headers = { 'User-Agent': 'xiaoheihe/1.1.52 (iPhone; iOS 10.3.3; Scale/2.00)' } configs = { 'host': 'localhost', 'user': '******', 'password': '******', 'db': 'pubg_steam' } db = DbHelper() db.connenct(configs) # 获取输入参数对应模式的前一百名简要数据 result = get_player_leaderboards(url, params, headers) if result: par = [] for data in get_rank(result, params): # rank排名保存到数据库 db.save_one_data_to_rank(data) if 'fpp' not in data['mode']: # 将后面爬取时需要提供的参数保存下来 par.append({ 'nickname': data['nickname'], 'season': data['season'], 'mode': data['mode'], 'fpp': '0'
time.localtime(time.time())), data['video_id'])) # 下载保存的文件名称 data['filename'] = data['description'] if data[ 'description'] else data['author'] + '_' + data['video_id'] yield data except Exception as e: print('get_video_info() error,', str(e)) data = {} data['result'] = 'error' yield data if __name__ == '__main__': configs = {'host': '***', 'user': '******', 'password': '******', 'db': '***'} db = DbHelper() db.connenct(configs) queue = Queue() Thread(target=put_into_queue, args=(queue, ), daemon=True).start() Thread(target=get_from_queue, args=(queue, db), daemon=True).start() while True: # 该循环是用来判断何时关闭数据库 try: data = queue.get_nowait() if data['type'] == 'getFinished': db.close() break except: print('spidering...') time.sleep(10)
dict = queue.get_nowait() for data in get_hot_comment(dict['resp']): data['song_id'] = dict['song_id'] db.save_one_data_to_hot_comment(data) # 存储热门评论 for d in get_comment(dict['resp']): d['song_id'] = dict['song_id'] db.save_one_data_to_comment(d) # 存储最新评论 queue.task_done() # 标记该数据已从队列中取出 except: print("queue is empty wait for a while") time.sleep(1) if __name__ == '__main__': # start_time = time.time() db = DbHelper() db.connenct(const.DB_CONFIGS) put_thread_pool = ThreadPool(3) get_thread_pool = ThreadPool(3) queue = ThreadManager().Queue( ) # 线程池之间通信需要用Manager().Queue(),线程间通信用Queue() comment_url = 'https://music.163.com/weapi/v1/resource/comments/R_SO_4_{}?csrf_token=' # 评论接口 random_str = create_random_str(16) params = get_params(const.FIRST_PARAM, const.FORTH_PARAM, random_str) encSecKey = get_encSecKey(random_str, const.SECOND_PARAM, const.THIRD_PARAM) form_data = {'params': params, 'encSecKey': encSecKey} response = get_html(const.DAY_LIST_URL)
def render_GET(self, request): macdb = DbHelper() res = macdb.uncensorp_fetch_all() msg = request.args['msg'][0] if 'msg' in request.args else '' output = """<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <title>House of Life Update Manager</title> <!-- CSS: implied media="all" --> <link rel="stylesheet" href="/css/style.css?v=2"> <link rel="stylesheet" href="/css/uncensor_domains.css"> <!-- Load jQuery --> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1"); </script> <script type="text/javascript"> function post_to_url(path, params, method) { method = method || "post"; // Set method to post by default, if not specified. // The rest of this code assumes you are not using a library. // It can be made less wordy if you use one. var form = document.createElement("form"); form.setAttribute("method", method); form.setAttribute("action", path); for(var key in params) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", key); hiddenField.setAttribute("value", params[key]); form.appendChild(hiddenField); } document.body.appendChild(form); form.submit(); } $(function() { $('#countries').change(function() { if ($('#countries option:selected').val()) { $('#cur_country_icon').attr('src', '/img/gif-flags/' + $('#countries option:selected').val().toLowerCase() + '.gif'); $('#cur_country_icon').show(); } }); }); </script> <style type="text/css"> #banner {""" if msg == "": output += """ display:none;""" output += """ } </style> </head> <body> <div id="container"> <header> <h1>Uncensor Proxy domains</h1> <p>Copyright © 2012, House of Life Property ltd. All rights reserved.<br /> Copyright © 2012, Crystalnix <[email protected]></p> </header> <div id="main" role="main"> <div id="banner"> %s </div> <p> <a href="javascript:void(0)" onclick="javascript:$('#add_form').show(); return false;">Add domain pair</a> </p> <form id="add_form" style="display:none" method="post"> <label for="countries"> Country: <select id="countries" name="iso"> <option value="">Choose from list...</option>""" % (msg) country_list = list(pycountry.countries) for country in country_list: output += '<option value="' + country.alpha2.encode('utf-8') + '">' + country.name.encode('utf-8') + '</option>' output += """ </select> <img id="cur_country_icon" style="display:none" src="/img/gif-flags/us.gif" alt="flag" title="US" /> </label> <label for="domain"> Original domain: <input type="text" id="domain" name="domain" /> </label> <input type="hidden" name="action" value="add" /> <input type="Submit" value="Submit" /> </form> <table id="domains"> <thead> <tr><th>Country</th> <th>Blocked domain</th> <th>Actions</th> </tr> </thead> <tbody>""" if len(res) == 0: output += """ <tr><td colspan="3" style="text-align: center">No domains in database</td></tr>""" ctr = 0 prevCountry = "" for row in res: output += """ <tr class="{5}"> <td><img src="/img/gif-flags/{0}.gif" alt="{1}" /> {1}</td> <td>{2}</td> <td><a href="javascript:if (confirm('Do you really want to delete this record?')) post_to_url('{3}', {{'id': '{4}', 'action':'delete'}})">Delete</a></td> </tr>""".format(row['iso'].lower(), pycountry.countries.get(alpha2=row['iso']).name, row['domain'], self.pathFromRoot, str(row['id']), 'even-row' if ctr % 2 == 0 else 'odd-row') ctr += 1 output += """ </tbody> </table> </div> <footer> </footer> </body> </html> """ macdb.cleanup() return output
BASE_DIR = Path(__file__).resolve().parent.parent.joinpath('files') # print(BASE_DIR) #D:\python_kurs\tg_bots\src\main.py #D:\python_kurs\tg_bots\files # D:\python_kurs\tg_bots\files from telegram.ext import (CommandHandler, Updater, Filters, CallbackContext, ConversationHandler, MessageHandler, CallbackQueryHandler) from telegram import (Update, ReplyKeyboardMarkup, InlineKeyboardButton, InlineKeyboardMarkup) from db_helper import DbHelper db = DbHelper() def start(update: Update, context: CallbackContext): from_user = update.message.from_user user = db.getUserById(from_user.id) if not user: db.createUser(from_user.id, from_user.username, from_user.first_name) categories = db.getCategories() if categories: buttons = generateButtons(categories) else: buttons = []
def render_GET(self, request): macdb = DbHelper() res = macdb.uncensor_fetch_all() msg = request.args['msg'][0] if 'msg' in request.args else '' output = """<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <title>House of Life Update Manager</title> <!-- CSS: implied media="all" --> <link rel="stylesheet" href="/css/style.css?v=2"> <link rel="stylesheet" href="/css/uncensor_domains.css"> <!-- Load jQuery --> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1"); </script> <script type="text/javascript"> function post_to_url(path, params, method) { method = method || "post"; // Set method to post by default, if not specified. // The rest of this code assumes you are not using a library. // It can be made less wordy if you use one. var form = document.createElement("form"); form.setAttribute("method", method); form.setAttribute("action", path); for(var key in params) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", key); hiddenField.setAttribute("value", params[key]); form.appendChild(hiddenField); } document.body.appendChild(form); form.submit(); } </script> <style type="text/css"> #banner {""" if msg == "": output += """ display:none;""" output += """ } </style> </head> <body> <div id="container"> <header> <h1>Uncensor domains</h1> <p>Copyright © 2011, House of Life Property ltd. All rights reserved.<br /> Copyright © 2011, Crystalnix <[email protected]></p> </header> <div id="main" role="main"> <div id="banner"> %s </div> <p> <a href="javascript:void(0)" onclick="javascript:$('#add_form').show(); return false;">Add domain pair</a> </p> <form id="add_form" style="display:none" method="post"> <label for="srcDomain"> Original domain: <input type="text" id="srcDomain" name="srcDomain" /> </label> <label for="dstDomain"> Domain to redirect to: <input type="text" id="dstDomain" name="dstDomain" /> </label> <input type="hidden" name="action" value="add" /> <input type="Submit" value="Submit" /> </form> <table id="domains"> <thead> <tr><th>Original domain</th> <th>Redirect domain</th> <th>Actions</th> </tr> </thead> <tbody>""" % (msg) if len(res) == 0: output += """ <tr><td colspan="3" style="text-align: center">No domains in database</td></tr>""" ctr = 0 for row in res: output += """ <tr class="{4}"> <td>{0}</td> <td>{1}</td> <td><a href="javascript:if (confirm('Do you really want to delete this record?')) post_to_url('{2}', {{'id': '{3}', 'action':'delete'}})">Delete</a></td> </tr>""".format(row['srcDomain'], row['dstDomain'], self.pathFromRoot, str(row['id']), 'even-row' if ctr % 2 == 0 else 'odd-row') ctr += 1 output += """ </tbody> </table> </div> <footer> </footer> </body> </html> """ macdb.cleanup() return output
import sys from db_helper import DbHelper if len(sys.argv) != 4: print('Incorrect usage. Specify args as: wineid no_bottles box') else: with DbHelper() as db_helper: connection = db_helper.connection cursor = db_helper.cursor query = """ INSERT INTO location (wineid, no, box, cellarversion) VALUES ({wineid}, {no}, {box}, 1) """.format(wineid=sys.argv[1], no=sys.argv[2], box=sys.argv[3]) cursor.execute(query) connection.commit() print("1 Record inserted successfully")
def render_GET(self, request): macdb = DbHelper() mainDict = loadJsonAndCheckIfLatestKeyExists(Config.bitpopUpdateInfoFile) bitpopInfo = mainDict['jsonData'] latestExists = mainDict['latestExists'] output = """<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <title>House of Life Update Manager</title> <!-- CSS: implied media="all" --> <link rel="stylesheet" href="/css/style.css?v=2"> </head> <body> <div id="container"> <header> <h1>House of Life Update Manager</h1> <p>Copyright © 2011, House of Life Property ltd. All rights reserved.<br /> Copyright © 2011, Crystalnix <[email protected]></p> </header> <div id="main" role="main"> <section id="win_updates">""" output += """ <h2>BitPop <img src="/img/windows-logo.png" alt="Windows logo" /></h2>""" if not latestExists: output += """ <p>There are no BitPop Windows updates available.</p>""" else: output += """ <p>Latest BitPop version: {0}</p>""".format(bitpopInfo["latest"]) output += """ <h3>Update files</h3> <ul> <li><a href="{0}">full update v{1}</a></li>""".format(getUpdateURL(bitpopInfo['latest']), bitpopInfo['latest']) if bitpopInfo.has_key('delta') and type(bitpopInfo['delta']) == type([]): for deltaFromVersion in bitpopInfo['delta']: output += """ <li><a href="{0}">delta update from v{1}</a></li>""".format( getUpdateURL(bitpopInfo['latest'], deltaFromVersion), deltaFromVersion) output += """ </ul>""" bitpopNewDict = loadJsonAndCheckIfLatestKeyExists(Config.bitpopNewUpdateInfoFile) bitpopNewInfo = bitpopNewDict['jsonData'] bitpopNewLatestExists = bitpopNewDict['latestExists'] if not bitpopNewLatestExists: output += """ <p><a href="{0}">Add new full version installer</a></p>""".format(self.pathFromRoot + '/new_full') else: output += """ <h3>Uploaded new version {0}</h3>""".format(bitpopNewInfo['latest']) if bitpopNewInfo.has_key('delta') and type(bitpopNewInfo['delta']) == type([]): output += """ <ul>""" for newDeltaFrom in bitpopNewInfo['delta']: output += """ <li>delta from {0}</li>""".format(newDeltaFrom) output += """ </ul>""" output += """ <p><a href="{0}">Add new delta update installer</a></p> <p><a href="{1}">Switch to new version ({2})</a></p>""".format( self.pathFromRoot + '/new_delta', self.pathFromRoot + '/switch', bitpopNewInfo['latest']) output += """ <p> <form style="display:none" id="clear_all" method="POST"> <input type="hidden" name="action" value="delete" /> </form> <a href="javascript:void(0)" onclick="(function () { document.getElementById('clear_all').submit();})()"> Clear all updates </a> </p> </section> <section id="mac_updates"> <h2>BitPop <img src="/img/apple-logo.png" alt="Apple logo" /></h2>""" macUpdates = macdb.fetch_several_latest(5) if len(macUpdates) != 0: output += """ <p>Latest BitPop version: {0}</p>""".format(macUpdates[0]["version"]) output += """ <h3>Update files:</h3> <ul>""" activeVersion = None try: activeStream = open(Config.macActiveVersionFile, "r") try: activeVersion = activeStream.readline() finally: activeStream.close() except IOError: pass for upd in macUpdates: output += """ <li><a href="{0}">full update v{1}{2}</a>""".format(getUpdateURLMac(upd['dmg_path']), upd['version'], ' (*)' if upd['version'] == activeVersion else '' ) output += """ <a href="/service/admin/mac/edit/{0}">Edit</a> | <a href="/service/admin/mac/delete/{0}" onclick="javascript: return confirm('Are you sure you want to delete this version?');"> Delete </a>""".format(upd['id']) output += """ </ul>""" # if macUpdates[0]['version'] != activeVersion: # output += """ # <p><a href="{0}">Make latest version active else: output += """ <p>There are no BitPop mac updates available.</p>""" output += """ <p><a href="{0}">Add new version archive</a></p>""".format(self.pathFromRoot + '/mac/new_full') output += """ </section> </div> <footer> </footer> </div> </body> </html>""" macdb.cleanup() return output
def __init__(self): self._db_hlp = DbHelper() self._cmd_list = self._get_cmd_list()
from db_helper import DbHelper from rec_utils import * # para generar pdf from flask import render_template, make_response import pdfkit app = Flask(__name__) app.config.from_pyfile("config.py") mysql = MySQL() mysql.init_app(app) conn = mysql.connect() cursor = conn.cursor() db = DbHelper(conn, cursor, mysql) IP = '189.149.97.142' def get_ratings_df_from_db(): rset = db.read('SELECT idSocio, idProducto, rating FROM valoracion') cols = ['reviewerID', 'asin', 'overall'] data = dict() for i, c in enumerate(cols): data[c] = [v[i] for v in rset] return pd.DataFrame(data, columns=cols) # DF_PATH = os.path.join('model', 'Grocery_and_Gourmet_Food_30_60.csv') # df = pd.read_csv(DF_PATH)
def render_GET(self, request): tr = re.compile('.*/(\d*)$') m = re.match(tr, request.path) if len(m.groups()) == 0: request.setResponseCode(400) # Bad request return "Error: Bad request." update_id = m.groups()[0] macdb = DbHelper() upd = macdb.fetch_by_id(int(update_id)) macdb.cleanup() if upd == None: request.setResponseCode(404) # Not found return "Error: Record with such id not found." output = """<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <title>House of Life Update Manager</title> <!-- CSS: implied media="all" --> <link rel="stylesheet" href="/css/style.css?v=2"> <!-- Load jQuery --> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1"); </script> <!-- Load TinyMCE --> <script type="text/javascript" src="/js/tiny_mce/jquery.tinymce.js"></script> <script type="text/javascript"> $().ready(function() { $('textarea.tinymce').tinymce({ // Location of TinyMCE script script_url : '/js/tiny_mce/tiny_mce.js', // General options theme : "advanced", plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist", // Theme options theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", theme_advanced_resizing : true, // Example content CSS (should be your site CSS) content_css : "/css/rel_notes.css" //, // Drop lists for link/image/media/template dialogs // template_external_list_url : "lists/template_list.js", // external_link_list_url : "lists/link_list.js", // external_image_list_url : "lists/image_list.js", // media_external_list_url : "lists/media_list.js", // Replace values for the template plugin // template_replace_values : { // username : "******", // staffid : "991234" // } }); }); </script> <!-- /TinyMCE --> </head>""" output += """ <body> <div id="container"> <header> <h1>Edit Release Notes for Mac version</h1> <p>Copyright © 2011, House of Life Property ltd. All rights reserved.<br /> Copyright © 2011, Crystalnix <[email protected]></p> </header> <div id="main" role="main"> <form method="post"> <label for="release_notes_text">Release Notes</label> <textarea class="tinymce" style="height: 400px" name="rel_notes" id="release_notes_text">{0}</textarea> <input type="hidden" name="rec_id" value="{1}" /> <input type="submit" value="Submit" /> </form> </div> <footer> </footer> </body> </html> """.format(cgi.escape(upd['rel_notes']), str(upd['id'])) return output
def render_GET(self, request): macdb = DbHelper() mainDict = loadJsonAndCheckIfLatestKeyExists( Config.bitpopUpdateInfoFile) bitpopInfo = mainDict['jsonData'] latestExists = mainDict['latestExists'] output = """<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <title>House of Life Update Manager</title> <!-- CSS: implied media="all" --> <link rel="stylesheet" href="/css/style.css?v=2"> </head> <body> <div id="container"> <header> <h1>House of Life Update Manager</h1> <p>Copyright © 2011, House of Life Property ltd. All rights reserved.<br /> Copyright © 2011, Crystalnix <[email protected]></p> </header> <div id="main" role="main"> <section id="win_updates">""" output += """ <h2>BitPop <img src="/img/windows-logo.png" alt="Windows logo" /></h2>""" if not latestExists: output += """ <p>There are no BitPop Windows updates available.</p>""" else: output += """ <p>Latest BitPop version: {0}</p>""".format(bitpopInfo["latest"]) output += """ <h3>Update files</h3> <ul> <li><a href="{0}">full update v{1}</a></li>""".format( getUpdateURL(bitpopInfo['latest']), bitpopInfo['latest']) if bitpopInfo.has_key('delta') and type( bitpopInfo['delta']) == type([]): for deltaFromVersion in bitpopInfo['delta']: output += """ <li><a href="{0}">delta update from v{1}</a></li>""".format( getUpdateURL(bitpopInfo['latest'], deltaFromVersion), deltaFromVersion) output += """ </ul>""" bitpopNewDict = loadJsonAndCheckIfLatestKeyExists( Config.bitpopNewUpdateInfoFile) bitpopNewInfo = bitpopNewDict['jsonData'] bitpopNewLatestExists = bitpopNewDict['latestExists'] if not bitpopNewLatestExists: output += """ <p><a href="{0}">Add new full version installer</a></p>""".format( self.pathFromRoot + '/new_full') else: output += """ <h3>Uploaded new version {0}</h3>""".format( bitpopNewInfo['latest']) if bitpopNewInfo.has_key('delta') and type( bitpopNewInfo['delta']) == type([]): output += """ <ul>""" for newDeltaFrom in bitpopNewInfo['delta']: output += """ <li>delta from {0}</li>""".format(newDeltaFrom) output += """ </ul>""" output += """ <p><a href="{0}">Add new delta update installer</a></p> <p><a href="{1}">Switch to new version ({2})</a></p>""".format( self.pathFromRoot + '/new_delta', self.pathFromRoot + '/switch', bitpopNewInfo['latest']) output += """ <p> <form style="display:none" id="clear_all" method="POST"> <input type="hidden" name="action" value="delete" /> </form> <a href="javascript:void(0)" onclick="(function () { document.getElementById('clear_all').submit();})()"> Clear all updates </a> </p> </section> <section id="mac_updates"> <h2>BitPop <img src="/img/apple-logo.png" alt="Apple logo" /></h2>""" macUpdates = macdb.fetch_several_latest(5) if len(macUpdates) != 0: output += """ <p>Latest BitPop version: {0}</p>""".format( macUpdates[0]["version"]) output += """ <h3>Update files:</h3> <ul>""" activeVersion = None try: activeStream = open(Config.macActiveVersionFile, "r") try: activeVersion = activeStream.readline() finally: activeStream.close() except IOError: pass for upd in macUpdates: output += """ <li><a href="{0}">full update v{1}{2}</a>""".format( getUpdateURLMac(upd['dmg_path']), upd['version'], ' (*)' if upd['version'] == activeVersion else '') output += """ <a href="/service/admin/mac/edit/{0}">Edit</a> | <a href="/service/admin/mac/delete/{0}" onclick="javascript: return confirm('Are you sure you want to delete this version?');"> Delete </a>""".format(upd['id']) output += """ </ul>""" # if macUpdates[0]['version'] != activeVersion: # output += """ # <p><a href="{0}">Make latest version active else: output += """ <p>There are no BitPop mac updates available.</p>""" output += """ <p><a href="{0}">Add new version archive</a></p>""".format( self.pathFromRoot + '/mac/new_full') output += """ </section> </div> <footer> </footer> </div> </body> </html>""" macdb.cleanup() return output
def render_POST(self, request): macdb = DbHelper() versionRegex = re.compile('^\d+\.\d+\.\d+\.\d+$') if not versionRegex.match(request.args['newVersion'][0]): request.setResponseCode(400) # Bad request return "Error: malformed version number." latest = macdb.fetch_latest() if latest != None and versionCompare(latest['version'], request.args['newVersion'][0]) != -1: request.setResponseCode(400) # Bad request return "Error: version number invalid. Supply version number greater than old version." newRecord = {}; newRecord['version'] = request.args['newVersion'][0] newRecord['dmg_path'] = os.path.join(Config.bitpopDirectory, 'mac', 'BitPop-' + newRecord['version'] + '.dmg') newRecord['dmg_size'] = str(len(request.args['fileToUpload'][0])) outDir = os.path.join(Config.bitpopDirectory, 'mac') if not os.path.exists(outDir): os.mkdir(outDir, 0755) elif not os.path.isdir(outDir): os.remove(outDir) os.mkdir(outDir, 0755) filename = newRecord['dmg_path'] try: outputStream = open(filename, 'wb') try: outputStream.write(request.args['fileToUpload'][0]) finally: outputStream.close() # sha = hashlib.new('sha1') # sha.update(request.args['fileToUpload'][0]) # hash = base64.b64encode(sha.digest()) os.system('openssl dgst -sha1 -binary < "{0}" | openssl dgst -dss1 -sign "dsa_priv.pem" | \ openssl enc -base64 > sig.txt'.format(filename)) sig = open('sig.txt', 'r') try: tsig = sig.readline() finally: sig.close() # md = EVP.MessageDigest('sha1') # md.update(request.args['fileToUpload'][0]) # digest = md.final() # # dsa = DSA.load_key(Config.dsaPrivateKeyFile) # sig = dsa.sign_asn1(digest) newRecord['dsa_signature'] = tsig.strip('\n\r\t ') newRecord['rel_notes'] = request.args['releaseNotes'][0]; macdb.insert(newRecord) activeStream = open(Config.macActiveVersionFile, 'w') try: activeStream.write(newRecord['version'] + "\n") finally: activeStream.close() except IOError: request.setResponseCode(500) # Internal server error return "Error: Internal Server Error. Failed to do some file operation." macdb.cleanup() return "OK. File was successfully uploaded to server."
def render_POST(self, request): macdb = DbHelper() versionRegex = re.compile('^\d+\.\d+\.\d+\.\d+$') if not versionRegex.match(request.args['newVersion'][0]): request.setResponseCode(400) # Bad request return "Error: malformed version number." latest = macdb.fetch_latest() if latest != None and versionCompare( latest['version'], request.args['newVersion'][0]) != -1: request.setResponseCode(400) # Bad request return "Error: version number invalid. Supply version number greater than old version." newRecord = {} newRecord['version'] = request.args['newVersion'][0] newRecord['dmg_path'] = os.path.join( Config.bitpopDirectory, 'mac', 'BitPop-' + newRecord['version'] + '.dmg') newRecord['dmg_size'] = str(len(request.args['fileToUpload'][0])) outDir = os.path.join(Config.bitpopDirectory, 'mac') if not os.path.exists(outDir): os.mkdir(outDir, 0755) elif not os.path.isdir(outDir): os.remove(outDir) os.mkdir(outDir, 0755) filename = newRecord['dmg_path'] try: outputStream = open(filename, 'wb') try: outputStream.write(request.args['fileToUpload'][0]) finally: outputStream.close() # sha = hashlib.new('sha1') # sha.update(request.args['fileToUpload'][0]) # hash = base64.b64encode(sha.digest()) os.system( 'openssl dgst -sha1 -binary < "{0}" | openssl dgst -dss1 -sign "dsa_priv.pem" | \ openssl enc -base64 > sig.txt'.format(filename)) sig = open('sig.txt', 'r') try: tsig = sig.readline() finally: sig.close() # md = EVP.MessageDigest('sha1') # md.update(request.args['fileToUpload'][0]) # digest = md.final() # # dsa = DSA.load_key(Config.dsaPrivateKeyFile) # sig = dsa.sign_asn1(digest) newRecord['dsa_signature'] = tsig.strip('\n\r\t ') newRecord['rel_notes'] = request.args['releaseNotes'][0] macdb.insert(newRecord) activeStream = open(Config.macActiveVersionFile, 'w') try: activeStream.write(newRecord['version'] + "\n") finally: activeStream.close() except IOError: request.setResponseCode(500) # Internal server error return "Error: Internal Server Error. Failed to do some file operation." macdb.cleanup() return "OK. File was successfully uploaded to server."
data['beReplied_user'] = None data['beReplied_content'] = None data['beReplied_like_count'] = None data['beReplied_comment_time'] = None print('{}\tget user:{} comment'.format( time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())), data['user'])) yield data except Exception as e: print('get_comment_info() error,', str(e)) data = {} data['result'] = 'error' yield data if __name__ == '__main__': configs = {'host': '***', 'user': '******', 'password': '******', 'db': '***'} db = DbHelper() db.connenct(configs) video_id_list = db.find_today_video() for video_id in video_id_list: comment_api = 'https://jokeai.zongcaihao.com/douyin/v292/comment/list?aweme_id={}&cursor=0'.format( video_id['video_id']) print(comment_api) for comment_data in get_comment(comment_api): if comment_data['result'] == 'success': db.save_one_data_to_comment(comment_data) elif comment_data['result'] == 'error': continue
def __init__(self, name): db = DbHelper() self.all_players = db.query_all_players() self.player = db.query_player(name) return
f.write(content) self.log.debug('{}词库下载完成'.format(filename)) print('{}词库下载完成'.format(filename)) def start(self, datas): self.pool.map(self.download, datas) # 一行代码实现多线程,大致相当于下面的代码,这种使用线程池的多线程的优势在于编写简单, # 但是只适用于所有需要处理的数据都已经生成,而且相对于正常写线程来说不够灵活 # for data in datas: # download(data) if __name__ == '__main__': start = time.time() configs = {'host': '***', 'user': '******', 'password': '******', 'db': '***'} db = DbHelper() db.connenct(configs) basedir = os.getcwd() download_dir = os.path.join(basedir, 'download\\') # print(download_dir) if not os.path.exists(download_dir): os.mkdir(download_dir) datas = db.find_all_detail() downloader = Downloader() downloader.start(datas) db.close() end = time.time() print('耗时:', end - start)
def render_GET(self, request): macdb = DbHelper() res = macdb.uncensorp_fetch_all() msg = request.args['msg'][0] if 'msg' in request.args else '' output = """<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <title>House of Life Update Manager</title> <!-- CSS: implied media="all" --> <link rel="stylesheet" href="/css/style.css?v=2"> <link rel="stylesheet" href="/css/uncensor_domains.css"> <!-- Load jQuery --> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1"); </script> <script type="text/javascript"> function post_to_url(path, params, method) { method = method || "post"; // Set method to post by default, if not specified. // The rest of this code assumes you are not using a library. // It can be made less wordy if you use one. var form = document.createElement("form"); form.setAttribute("method", method); form.setAttribute("action", path); for(var key in params) { var hiddenField = document.createElement("input"); hiddenField.setAttribute("type", "hidden"); hiddenField.setAttribute("name", key); hiddenField.setAttribute("value", params[key]); form.appendChild(hiddenField); } document.body.appendChild(form); form.submit(); } $(function() { $('#countries').change(function() { if ($('#countries option:selected').val()) { $('#cur_country_icon').attr('src', '/img/gif-flags/' + $('#countries option:selected').val().toLowerCase() + '.gif'); $('#cur_country_icon').show(); } }); }); </script> <style type="text/css"> #banner {""" if msg == "": output += """ display:none;""" output += """ } </style> </head> <body> <div id="container"> <header> <h1>Uncensor Proxy domains</h1> <p>Copyright © 2012, House of Life Property ltd. All rights reserved.<br /> Copyright © 2012, Crystalnix <[email protected]></p> </header> <div id="main" role="main"> <div id="banner"> %s </div> <p> <a href="javascript:void(0)" onclick="javascript:$('#add_form').show(); return false;">Add domain pair</a> </p> <form id="add_form" style="display:none" method="post"> <label for="countries"> Country: <select id="countries" name="iso"> <option value="">Choose from list...</option>""" % (msg) country_list = list(pycountry.countries) for country in country_list: output += '<option value="' + country.alpha2.encode( 'utf-8') + '">' + country.name.encode('utf-8') + '</option>' output += """ </select> <img id="cur_country_icon" style="display:none" src="/img/gif-flags/us.gif" alt="flag" title="US" /> </label> <label for="domain"> Original domain: <input type="text" id="domain" name="domain" /> </label> <input type="hidden" name="action" value="add" /> <input type="Submit" value="Submit" /> </form> <table id="domains"> <thead> <tr><th>Country</th> <th>Blocked domain</th> <th>Actions</th> </tr> </thead> <tbody>""" if len(res) == 0: output += """ <tr><td colspan="3" style="text-align: center">No domains in database</td></tr>""" ctr = 0 prevCountry = "" for row in res: output += """ <tr class="{5}"> <td><img src="/img/gif-flags/{0}.gif" alt="{1}" /> {1}</td> <td>{2}</td> <td><a href="javascript:if (confirm('Do you really want to delete this record?')) post_to_url('{3}', {{'id': '{4}', 'action':'delete'}})">Delete</a></td> </tr>""".format(row['iso'].lower(), pycountry.countries.get(alpha2=row['iso']).name, row['domain'], self.pathFromRoot, str(row['id']), 'even-row' if ctr % 2 == 0 else 'odd-row') ctr += 1 output += """ </tbody> </table> </div> <footer> </footer> </body> </html> """ macdb.cleanup() return output