def yunxing(): global u global w global z global x global k global b global texthuizong global cp texthuizong = "" print('-------------新浪新闻抓取程序,搞个大新闻!-------------\n') print('------请用管理员权限运行,否则将无法保存新闻,安姆安格瑞!------\n') chushihua() shuru() u = 0 w = 200 z = y - x k = 0 b = 1 now = datetime.now() liebiaoxunhuan() zongshu = len(huizong) print(zongshu) df = pandas.DataFrame(huizong) name1 = str(name) with sqlite3.connect('xinwen.sqlite') as db: df.to_sql(name1, con = db) db.close() name2 = name1 + "cipin" end = datetime.now() for i in huizong: texthuizong += i["neirong"] print("正在进行词频统计------------------------------") cipin(texthuizong) print("词频统计完成!!!!!!!!!!!!!!!!!!!!!!!!\n") cipinxieru = pandas.DataFrame(tongji[0:cp]) with sqlite3.connect('xinwen.sqlite') as db2: cipinxieru.to_sql(name2, con = db2) db2.close() print(now) print(end) print("程序耗时: " + str(end-now) + "\n" + "\n新闻存放在本程序所在目录的xinwen sqlite数据库%s数据表中\n词频数据存放在%scipin数据表中\n" %(name1,name1)) jieshu = input("输入r重新运行本程序,继续学习一个!输入其他字符结束程序!\n") if jieshu == "r": yunxing()
def generate_questions(self,tags): ''' Returns a list of Question objects that match the specified set of tags. The tags specify the subject of the question and includes the country name that the question will be about. ''' from question import Question import sqlite3 as sqlite db = sqlite.connect(self.database_path); cur = db.cursor(); q_list = list() if len(tags) == 1: cur.execute(get_question_by_tag(tags[0])) else: cur.execute(get_question_by_tags(tags)) for row in cur.fetchall(): #???? = row.split(",") #extract values text = None answer = None choices = None q_id = None q_list.append(Question(text, answer, choices, q_id)) self.db = sqlite.close() return q_list
def runQuery(query): try: db = mysql.connector.connect( host='localhost', database='db_theatre', user='******', password='******') if db.is_connected(): cursor = db.cursor(buffered = True) cursor.execute(query) db.commit() return cursor.fetchall() except Error as e: #Some error occured return e.args[1] finally: db.close() #Couldn't connect to MySQL return None
def fetch(name): try: sq.connect(dataBase) cursor=sq.execute("SELECT CRYPT FROM USER WHERE NAME = "+str(name)) crypt=cursor[0][0] sq.close() key = r.read() if key=="o": print("We couldn't detect your key within 10secs") return "Failed" ans=cry.deXor(key,crypt) if(ans=="Failed"): print("A Wrong Key is been in put as it Failed unlocking") exit() else: return ans except: print("there was a problem fetching your data!") return "Failed"
def generate_countries(self, start_country, number): ''' Returns a list of countries of the specifid number which includes the specified starting country. The list is a list of hashes that map information about the country as specific attributes. For example: list[0]["name"] = the name of the first country in the list. list[4]["tags"] = a tuple of tags for the 5th country in the list. The current set of expected attributes are: "name" - the name of the country "tags" - a tuple of tags for this country (including the country name) ''' import sqlite3 as sqlite self.db = sqlite.connect(self.database_path) c = self.db.cursor() id_set = set() chosen_set = set() c.execute( query_countries() ) for row in c.fetchall(): c_id, name = row.split(",") if name == start_country: chosen_set.add(c_id) id_set.add(c_id) from random import choice if len(id_set) > number: while len(chosen_set) < number: chosen_set.add( random.choice(id_set) ) else: chosen_set = id_set info_hash_list = list() for c_id in chosen_set: c.execute( get_tags(c_id) ) info_dict = dict() for row in c.fetchall(): #??? = row.split(",") #extract the info for this country name = None tags = None # put info into the dict info_dict["name"] = name info_dict["tags"] = tags info_hash_list.append(info_dict) self.db = sqlite.close() return info_hash_list
def __delete__(self): return sqlite3.close(self.dbConnector)
image text, listprice int, offerprice int, url text, type text, gender text ); """) self.conn.commit() def get_clients(self): self.cursor.execute("SELECT client_id, folder_id FROM clients;") clients = self.cursor.fetchall() cursor2 = self.conn.cursor() def reset(self): self.cursor.execute("DROP TABLE IF EXISTS clothes;") self.conn.commit() def close(self): self.conn.close() def get_all_clothes(self): return self.cursor.execute("SELECT * FROM clothes;") if __name__ == "__main__": db = Database() db.fix_img_url() db.close()