def main(): """""" root_url = "https://pan.baidu.com/s/" # source_url = "https://pan.baidu.com/pcloud/feed/getdynamiclist?auth_type=1&filter_types=11000&query_uk=1404980556&category=0&limit=50&start=2&bdstoken=2cef3aa5bc4fa2a5f3c29a0244e13838&channel=chunlei&clienttype=0&web=1&logid=MTU0OTUzNjg5NTc0MzAuMzc0MTY0OTE5Njk2ODM4Ng==" user_agent = UserAgent().chrome print(user_agent) headers = { "User-Agent": user_agent, "Cookie": "BAIDUID=B665C57519BB1CE733014F986955D850:FG=ww; PSTM=1524450639; BIDUPSID=4E742698B7CE1AA938C285FED0123F7A; PANWEB=ww; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; MCITY=-54028%3A; BDCLND=FdI5VGiLGiuP50G3DmS9Sv%2BT5puEraBA80TAnYJd7LM%3D; cflag=13%3A3; delPer=0; PSINO=2; BDUSS=0hxQWtLZVlEYW1HTjB2RXpJZmRIa3ZFdUZ1UXp1UmQ4R3NrQ0lmTXROOWVXb05jQUFBQUFBJCQAAAAAAAAAAAEAAAADU5O6eDkyMDIzMjc5NgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAF7NW1xezVtcV; STOKEN=8ee50ac349feeb50e7e416fc38f3d2662813e837d7f044ae0a58ae812988a2d9; SCRC=24a1fa6c4edc40cba18ff8924ac79c09; Hm_lvt_7a3960b6f067eb0085b7f96ff5e660b0=1549182728,1549509635,1549510597,1549520225; Hm_lvt_f5f83a6d8b15775a02760dc5f490bc47=1549509786,1549510604,1549520259; BDRCVFR[feWj1Vr5u3D]=I67x6TjHwwYf0; BDRCVFR[M7pOaqtZgJR]=I67x6TjHwwYf0; H_PS_PSSID=1445_21090_28328_28413; Hm_lpvt_f5f83a6d8b15775a02760dc5f490bc47=1549537336; recommendTime=android2019-ww-31%2017%3A00%3A00; Hm_lpvt_7a3960b6f067eb0085b7f96ff5e660b0=1549537453; PANPSC=13191783871572786376%3AnSvEWpGhaFom0wdWVT9TBXiC6e0Ll37p5Qm%2FyHlw2fqYXvTamKXvPHgXofrWESI4fJ06i7Fpl5f%2FHSZRhh6%2BPa1Sr93PEHDiDv6sF2krPB6pWetz1AjD6SeKHrlyURG2vIcMCeE%2BEzPl0236xFtTr1QxIuFgE8LFzlMymqcoIUw%3D", "Connection": "keep-alive" } result_url_list = database.select_all_complete_url() ## 得到url list 然后for循环每个url 进行数据搜索 result_source_url_list = source_url_list.cons_source_url_list() for source_url in result_source_url_list: res = requests.get(source_url, headers=headers) # print(res.status_code) # print(res.content) result_dict = eval(str(res.content.decode())) if (result_dict.get("errno") == 2): print("~~~~~~~~~~end~~~~~~~~~~~~~~") break result_list = result_dict.get("records") # print(result_list) for each_file in result_list: title = each_file.get("title").replace("//", "/").replace( "'", "").replace("‘", "") short_url = each_file.get("shorturl") print(title) file_list = each_file.get("filelist") file_name_list = [] if file_list: for each_file1 in file_list: file_name = each_file1.get("server_filename").replace( "//", "/").replace("'", "").replace("‘", "") file_name_list.append(file_name) title = title + (str(file_name_list)).replace("'", "").replace( "‘", "") if len(title) > 220: title = title[:210] # print(short_url) # complete_url = "https://pan.baidu.com/s/" + short_url if short_url not in result_url_list: database.insert_data(title, short_url) print(title) import time time.sleep(5) database.close_db()
def next_high_score(user): global db try: score = database.get_score(user) c=database.open_db() command = "SELECT user,pts FROM accounts WHERE pts>? ORDER BY pts ASC" c.execute(command, (score,)) data = c.fetchone() database.close_db() except: print "Error: could the next higher score" return None return data
def select_test(message): conn, cursor = database.open_db(database.db_name) query = f"SELECT id from {database.tests_t}" result = [elem[0] for elem in cursor.execute(query).fetchall()] result = list(set(result)) test_id = random.choice(result) query = f"UPDATE {database.status_t} SET test_id='{test_id}', question_number='0', score='0' WHERE id='{message.chat.id}'" cursor.execute(query) query = f"SELECT interest FROM {database.users_t} WHERE id='{message.chat.id}'" interest = cursor.execute(query).fetchall()[0][0] bot.send_message(message.chat.id, interest) bot.send_message(message.chat.id, messages.test_info_message + test_id) database.close_db(conn, cursor) send_question(message)
def num_gifs_flagged(): global db try: c=database.open_db() command = "SELECT * FROM flaggedgif" c.execute(command) data = c.fetchall() database.close_db() except: print "Error: could not get number of gifs flagged" return 0 count = 0 for entry in data: count += 1 return count
def num_users(): global db try: c=database.open_db() command = "SELECT * FROM accounts" c.execute(command) data = c.fetchall() database.close_db() except: print "Error: could not get number of users" return 0 count = 0 for entry in data: count += 1 return count
def words_solved(): global db try: c=database.open_db() command = "SELECT pts FROM accounts" c.execute(command) data = c.fetchall() database.close_db() except: print "Error: could not get words solved" return 0 total = 0 for entry in data: total += entry[0]/100 return total
def send_question(message): conn, cursor = database.open_db(database.db_name) query = f"SELECT test_id, question_number, score FROM {database.status_t} WHERE id='{message.chat.id}'" result = cursor.execute(query).fetchall()[0] test_id = int(result[0]) question_number = int(result[1]) score = int(result[2]) # get number of questions in test query = f"SELECT * FROM {database.tests_t} WHERE id='{test_id}'" result = cursor.execute(query).fetchall() test_len = len(result) if question_number == 0: question_number += 1 elif 0 < question_number <= test_len: user_answer = message.text query = f"SELECT ans_1 FROM {database.tests_t} WHERE id='{test_id}' AND number='{question_number}'" correct_answer = cursor.execute(query).fetchall()[0][0] if user_answer == correct_answer: score += 1 bot.send_message(message.chat.id, messages.correct_answer_message) else: bot.send_message(message.chat.id, messages.incorrect_answer_message) question_number += 1 if question_number > test_len: bot.send_message( message.chat.id, 'Тест окончен\nВерных ответов: ' + str(score) + ' из ' + str(test_len)) database.set_status(message, config.wait) send_help(message) else: query = f"UPDATE {database.status_t} SET question_number='{question_number}', score='{score}'" cursor.execute(query) # send question query = f"SELECT question, ans_1, ans_2, ans_3, ans_4 FROM {database.tests_t} " \ f"WHERE id='{test_id}' AND number='{question_number}'" result = list(cursor.execute(query).fetchall()[0]) question = result[0] answers = result[1:] random.shuffle(answers) user_markup = telebot.types.ReplyKeyboardMarkup(True, True) user_markup.row(answers[0], answers[1]) user_markup.row(answers[2], answers[3]) bot.send_message(message.chat.id, question, reply_markup=user_markup) database.close_db(conn, cursor)
args["rank"] = str(i + 1) args["endpointVersion"] = fw.endpointVersion temp = ("%.2f" % args["percentage"]) args["percentage"] = temp args["webRootPath"] = fw.webRootPath most_popular_rows += popular_row_template.safe_substitute(args) render_args["unsafe_tableHead"] = popular_table_head render_args["unsafe_table"] = most_popular_rows render_args["tableTitle"] = "Items which are bought the most" elif filter == "leastpopular": least_popular = database.get_least_popular_items() least_popular_rows = "" for i in range(len(least_popular)): args = copy.copy(least_popular[i]) args["rank"] = str(i + 1) args["endpointVersion"] = fw.endpointVersion temp = ("%.2f" % args["percentage"]) args["percentage"] = temp args["webRootPath"] = fw.webRootPath least_popular_rows += popular_row_template.safe_substitute(args) render_args["unsafe_tableHead"] = popular_table_head render_args["unsafe_table"] = least_popular_rows render_args["tableTitle"] = "Items which are bought the least" fw.render("views/items/general", render_args) fw.render_footer(["navbar.js"]) database.close_db()
def teardown_request(exception): close_db()
def close_db_at_end_of_requests(e=None): close_db(e)
def close_db(error): database.close_db(error)
if '-' in codename: codename = codename.replace('-', '_').split('_')[0] name = NAMES[codename] version = txt.split('/')[-1].split('_')[4] child.text = f'{name} ({codename}) - {version}' for child in root.findall('./channel/item/link'): codename = child.text.split('/')[-1].split('_')[1] child.text = f'https://xiaomifirmwareupdater.com/firmware/{codename}' with open('../releases.xml', 'w', encoding='utf-8') as out: out.write(eT.tostring(root).decode()) def main(): """ XFU data generate script """ load_names() load_fw_devices() load_releases() generate_fw_md() generate_fw_updates_md() load_miui_devices() generate_miui_md() load_vendor_devices() generate_rss() if __name__ == '__main__': main() close_db()
def close_db_connection(exception): close_db()
def close_application(error): close_db()
time_hms = listA[0] python_dict = bf_depth.read_test('./depth/' + time_ymd + '/' + time_hms + '.json') bf_depth.read_json(python_dict, time_ymd, time_hms, i, 'ASK', 'savedb', db) bf_depth.read_json(python_dict, time_ymd, time_hms, i, 'BID', 'savedb', db) db.commit() i = i + 1 time_ymd = '20200513' file_list = os.listdir('./depth/' + time_ymd) i = 0 for file in file_list: print(str(i) + " - " + file) stringA = str(file) listA = stringA.split(".") time_hms = listA[0] python_dict = bf_depth.read_test('./depth/' + time_ymd + '/' + time_hms + '.json') bf_depth.read_json(python_dict, time_ymd, time_hms, i, 'ASK', 'savedb', db) bf_depth.read_json(python_dict, time_ymd, time_hms, i, 'BID', 'savedb', db) db.commit() i = i + 1 database.close_db(db)