def start(self): try: num = Handle.list_num() self.progressBar.setRange(0, num) k = 0 for i in Handle.start(): for j in i: self.info.insertPlainText(j) k += 1 self.progressBar.setValue(k) t = QtCore.QTime() t.start() while t.elapsed() < 1000: QtCore.QCoreApplication.processEvents() except requests.exceptions.ConnectionError: self.progressBar.setValue(0) self.info.append("连接失败!请检查网络") except Exception as e: self.progressBar.setValue(0) self.info.append("发生错误!请重试") self.info.append(str(e)) else: if num == 0: self.progressBar.setRange(0, 100) num = 100 self.progressBar.setValue(num) self.info.append("评估完成!") self.info.append("请自行检查是否全部评估,如有未知结果或未评估的请重试")
def try_go(): try: html = Handle.login(ui.user_name.text(), ui.password.text(), ui.yzm.text()) error = re.findall('<strong><font color="#990000">(.*?)</font></strong><br>', html.text) if error: ui.warn.setText(error[0]) ui.img.show_img() return control = requests.get("http://www.parallelc.cn/list.html") go_list = re.findall("#(.*)", control.text) right = 0 for i in go_list: if re.match(i, ui.user_name.text()): right = 1 break if right == 0: raise Exception("你没有使用权限!") except requests.exceptions.ConnectionError: ui.warn.setText("连接失败!请检查网络") except Exception as e: ui.img.show_img() ui.warn.setText("发生错误!" + str(e)) else: widget.close() ui1.clear() ui1.progressBar.setValue(0) info = Handle.get_info() ui1.number.setText(info[0]) ui1.user_name.setText(info[1]) widget1.show()
def show_img(self): self.setText("加载中...") try: Handle.load_img() except Exception: self.setText("加载失败") else: self.setPixmap(QtGui.QPixmap("code.jpg")) self.show()
def __init__(self, args=[], time=random.randint(2, 20), priority=5, description='TST'): E_Base.__init__(self, time, priority, description) self.handle = Handle.H_Worker().handle self.args = args
def handle(raw_msg): msg = MessageParser.Message(raw_msg) persondb.addPerson(msg.mfrom) # logs every person! if msg.chat.type == "private": log.debug("private message received") #chatsdb.addChat(msg.chat) chatid = msg.chat.id # add the user usersdb.addUser(msg.mfrom, chatid) user = usersdb.getUser(msg.mfrom) # received a message user is supposedly active user.isActive = True if user.accepted_terms == False: log.debug("handle privacy policy") Handle.handle_privacy_policy(bot, usersdb, user, msg.content) else: # flag to send main menu send_main_menu = True # check the content if there is piped some request send_main_menu = Handle.handle_content(msg.content, bot, user, categoriesdb, mediavotedb) # analyize content if msg.content.type == "text" and send_main_menu: # log the messages to the bot text = msg.content.text log_msg = text if len(text) < 244 else text[:241] + "..." log_msg = log_msg.encode("utf-8").decode( "ascii", "backslashreplace") log.debug("Message: " + log_msg) # handle the requests send_main_menu = Handle.handle_private_text( msg.content.text, bot, user, usersdb, categoriesdb, mediavotedb) if send_main_menu: Handle.send_main_menu(bot, user) #chatsdb.update() usersdb.update() categoriesdb.update() mediavotedb.update() persondb.update()
def setup(self): self.handle = Handle.HandleTotal()
# -*- coding: UTF-8 -*- import requests import bs4 import json import Handle resources_file_path = '/airportNameList.txt' scratch_url = 'https://data.variflight.com/profiles/profilesapi/search' def scratch_airport_name(scratch_url, old_airports): new_airports = [] data = requests.get(scratch_url).text all_airport_json = json.loads(data)['data']['list'] for airport_by_word in all_airport_json.values(): for airport in airport_by_word: if airport['profiles_city'] and airport['profiles_name'] not in old_airports: new_airports.append(airport['profiles_city'] + ',' + airport['profiles_name']) return new_airports if __name__ == '__main__': Handle.handle(resources_file_path, scratch_url, scratch_airport_name)
#!/usr/bin/python # -*- coding: UTF-8 -*- import requests import bs4 import json import Handle resources_file_path = '/trainNameList.txt' scratch_url = 'http://www.59178.com/checi/' def scratch_train_number(scratch_url, old_trains): new_trains = [] resp = requests.get(scratch_url) data = resp.text.encode(resp.encoding).decode('gb2312') soup = bs4.BeautifulSoup(data, "html.parser") a_trains = soup.find('table').find_all('a') for train in a_trains: if train.text not in old_trains and train.text: new_trains.append(train.text) return new_trains if __name__ == '__main__': Handle.handle(resources_file_path, scratch_url, scratch_train_number)
def query(raw_msg): query = MessageParser.CbkQuery(raw_msg, False) query.initOptionals() # warning user might not be in the database user = usersdb.getUser(query.person) log.debug(query.data) if query.data.startswith("rmacc"): scmd = query.data.split("_") ans = scmd[1] if ans == "yes": categoriesdb.deleteCategoryUser(user, mediavotedb) log.info("deleted categories") mediavotedb.deleteUserMedia(user) log.info("deleted media") usersdb.deleteUser(user) log.info("deleted user") BotWrappers.sendMessage(bot, user, "All data removed") bot.answerCallbackQuery(query.id, text='Removed') else: Handle.send_main_menu(bot, user) bot.answerCallbackQuery(query.id, text='Not removed') usersdb.update() elif query.data.startswith("remcat_"): st = query.data.split("_") if len(st) == 2: categoriesdb.deleteCategory(st[1]) bot.answerCallbackQuery(query.id, text='Deleted {}'.format(st[1])) else: bot.answerCallbackQuery(query.id, text='Delete cat somethings fucky') elif query.data.startswith("bancat_"): st = query.data.split("_") if len(st) == 2: categoriesdb.banCategory(st[1]) bot.answerCallbackQuery(query.id, text='Banned {}'.format(st[1])) else: bot.answerCallbackQuery(query.id, text='Ban cat somethings fucky') elif query.data.startswith("cp_"): # change page cmd_list = query.data.split("_") if len(cmd_list) < 4: raise Exception("list too short") page_n = int(cmd_list[2]) prev = True if cmd_list[3] == "prev" else False if cmd_list[1] == "cat": Handle.answer_categories_page(bot, user, categoriesdb, query, prev, page_n, mediavotedb) elif cmd_list[1] == "shortcat": Handle.answer_short_categories(bot, user, categoriesdb, query, prev, page_n) elif cmd_list[1] == "catlist": cat_list = categoriesdb.getValues() p = Pages.CategoryList(page_n, cat_list, query) p.check_answer(bot, user, prev) elif cmd_list[1] == "utop": ulist = Handle.getSortedUserList(usersdb) p = Pages.UserTopPages(page_n, ulist, query) p.check_answer(bot, user, prev) elif query.data.startswith("vote"): # increase the upvote count or downvote count cmd_list = query.data.split("_") upvote = True if cmd_list[1] == "up" else False dmedia = mediavotedb.database[int(cmd_list[2])] media = dmedia.getData() if user.hash_id in media.voters_id: bot.answerCallbackQuery(query.id, text='Already voted') else: if upvote: media.upvotes += 1 else: media.downvotes += 1 # add to the media the voters media.voters_id.append(user.hash_id) mediavotedb.setMedia(media) # give / subtract a point from the media owner media_user = usersdb.hGetUser(media.creator_hash_id) coin = str(NumberFormatter.PellaCoins(1)) if upvote: media_user.pella_coins += 1 BotWrappers.sendMessage( bot, media_user, "Somebody upvoted your media. You received " + coin) else: media_user.pella_coins -= 1 BotWrappers.sendMessage( bot, media_user, "Somebody downvoted your media. You lost " + coin) usersdb.setUser(media_user) # give a point to the voter user.pella_coins += 1 BotWrappers.sendMessage(bot, user, "You voted a media. You received " + coin) usersdb.setUser(user) mediavotedb.update() usersdb.update() bot.answerCallbackQuery(query.id, text='Voted!') elif query.data.startswith("hide"): # hide the picture scmd = query.data.split("_") uid = scmd[1] if uid not in user.no_show_ids: user.no_show_ids.append(uid) bot.answerCallbackQuery(query.id, text='Hidden') elif query.data.startswith("report"): # send report to the admins # send the creator a message with the option to ban/delete media # send the category creator a message with the option to delete the # media pass elif query.data.startswith("delete"): # delete picture if enough money pass else: bot.answerCallbackQuery(query.id, text='what?')
def init_login(self): return Handle.HandleLogin()
def init_index(self): return Handle.HandleIndex()
scratch_url = 'http://www.smskb.com/train/' def scratch_train_station(scratch_url, old_stations): new_stations = [] provinces_eng = ("Anhui", "Beijing", "Chongqing", "Fujian", "Gansu", "Guangdong", "Guangxi", "Guizhou", "Hainan", "Hebei", "Heilongjiang", "Henan", "Hubei", "Hunan", "Jiangsu", "Jiangxi", "Jilin", "Liaoning", "Ningxia", "Qinghai", "Shandong", "Shanghai", "Shanxi", "Shanxisheng", "Sichuan", "Tianjin", "Neimenggu", "Xianggang", "Xinjiang", "Xizang", "Yunnan", "Zhejiang") provinces_chi = ("安徽", "北京", "重庆", "福建", "甘肃", "广东", "广西", "贵州", "海南", "河北", "黑龙江", "河南", "湖北", "湖南", "江苏", "江西", "吉林", "辽宁", "宁夏", "青海", "山东", "上海", "陕西", "山西", "四川", "天津", "内蒙古", "香港", "新疆", "西藏", "云南", "浙江") for i in range(0, provinces_eng.__len__(), 1): cur_url = scratch_url + provinces_eng[i] + ".htm" resp = requests.get(cur_url) data = resp.text.encode(resp.encoding).decode('gbk') soup = bs4.BeautifulSoup(data, "html.parser") a_stations = soup.find('left').find('table').find_all('a') for station in a_stations: if station.text not in old_stations: new_stations.append(provinces_chi[i] + ',' + station.text) return new_stations if __name__ == '__main__': Handle.handle(resources_file_path, scratch_url, scratch_train_station)
def __init__(self): self.Handle = Handle.Handle() self.userCF_alg = userCF.userCF() self.itemCF_alg = itemCF.itemCF() self.display = display.display() self.ID = "4"
def __init__(self, args=[], time=60, priority=10, description='TST'): E_Base.__init__(self, time, priority, description) self.handle = Handle.H_Test().handle self.args = args E_Test.idx += 1
def reset(self): event = Event(1, 0, Handle.H_Init().handle, (), 0, 'NEWINIT') scheduler._queue = [event] print 'Queue reset\n'
def __init__(self, args, time=1, priority=1, description='NORM'): E_Base.__init__(self, time, priority, description) self.handle = Handle.H_RescueVNet().handle self.args = args
def __init__(self, time=8, priority=3, description='NORM'): E_Base.__init__(self, time, priority, description) self.handle = Handle.H_PerceiveVNet().handle self.args = ()
def __init__(self): E_Base.__init__(self, time=2, priority=2, description='NORM') self.handle = Handle.H_Init().handle self.args = ()
def __init__(self, args=[], time=3, priority=5, description='NORM'): E_Base.__init__(self, time, priority, description) self.handle = Handle.H_StopOffAV().handle self.args = args
import Handle # 文件保存路径,相对路径 resources_file_path = '/cinemaNameList.txt' scratch_url = 'http://theater.mtime.com/China_Beijing/' # scratch data with define url def scratch_latest_movies(scratch_url, old_movies): data = requests.get(scratch_url).text soup = bs4.BeautifulSoup(data, "html.parser") new_movies = [] new_movies_json = json.loads( soup.find('script', text=re.compile("var hotplaySvList")).text.split("=")[1].replace(";", "")) coming_movies_data = soup.find_all('li', class_='i_wantmovie') # 上映的电影 for movie in new_movies_json: move_name = movie['Title'] if move_name not in old_movies: new_movies.append(movie['Title']) # 即将上映的电影 for coming_movie in coming_movies_data: coming_movie_name = coming_movie.h3.a.text if coming_movie_name not in old_movies and coming_movie_name not in new_movies: new_movies.append(coming_movie_name) return new_movies if __name__ == '__main__': Handle.handle(resources_file_path, scratch_url, scratch_latest_movies)
import click import os, glob import Handle as Hl from prompt_toolkit import prompt from prompt_toolkit.history import FileHistory from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from prompt_toolkit.completion import WordCompleter cmdHandler = Hl.Handle() @click.group() # @click.option("--ws", help="specifica il workspace caricato") # @click.option("--path", ="Percorso file di un ontologia da caricare o da serializzare") # @click.option("--eg", help="Nome dell'esempio da mostrare {toystory | metastaticcancer}") # @click.option('--about', help="Lista nodi from") # @click.option('--to', help="Lista nodi to") # @click.option('--prob', '-p', is_flag=True, help="calcola le probabilita' di tutte le entita' presenti nel grafo") # @click.command("bayes", help="Apre Shell interattiva in cui e' possibile fare inferenza nella rete bayesiana") def main(): pass @main.command(help="Mostra le ontologie presenti nella cartella di lavoro" ) #mostra tutte le ontologie def show(): cmdHandler.show_ontologies() @main.command(help="Visualizza la rete bayesiana")
def init_art_r_pass(self): return Handle.HandleleArticleReviewPass()
#!/usr/bin/python # -*- coding: UTF-8 -*- import requests import bs4 import Handle resources_file_path = '/flightNameList.txt' scratch_url = 'http://www.variflight.com/sitemap.html?AE71649A58c77=' def scratch_flight_number(scratch_url, old_flights): new_flights = [] data = requests.get(scratch_url).text soup = bs4.BeautifulSoup(data, "html.parser") a_flights = soup.find('div', class_='list').find_all('a', recursive=False) for flight in a_flights: if flight.text not in old_flights and flight.text != '国内航段列表': new_flights.append(flight.text) return new_flights if __name__ == '__main__': #执行scratch_flight_number函数,传入resources_file_path,scratch_url参数 Handle.handle(resources_file_path, scratch_url, scratch_flight_number)
def setup(self): self.handle_index = Handle.HandleIndex() self.handle_css = Handle.HandleCss()