def log(): if args.number: cursor.execute("SELECT * FROM history ORDER BY date DESC LIMIT ?", str(args.number)) rows = cursor.fetchall() for task in rows: print("On " + time.asctime(time.localtime(task[0])) + " you worked for " + helper.parseTime(task[3]) + " on " + helper.parseTask(task)) elif args.days: cursor.execute("SELECT * FROM history WHERE date > ?", [str(time.time() - 86400 * args.days)]) rows = cursor.fetchall() for task in rows: print("On " + time.asctime(time.localtime(task[0])) + " you worked for " + helper.parseTime(task[3]) + " on " + helper.parseTask(task)) else: cursor.execute("SELECT * FROM history ORDER BY date DESC LIMIT ?", str(5)) rows = cursor.fetchall() for task in rows: print("On " + time.asctime(time.localtime(task[0])) + " you worked for " + helper.parseTime(task[3]) + " on " + helper.parseTask(task))
def saveServralNews(category): try: count = 0 page = 0 while count < num_maxNewsEachCategory: start = page * 40 newsList = getNewsContent(category, start) for news in newsList["list"]: if(count>=num_maxNewsEachCategory): return newsContent = reg.sub('', news["content"]) newsContent = re.sub('(\s){2,}', ' ', newsContent).strip() if (newsContent.strip() == ""): continue length = newsContent.__len__() result = helper.count_from_str(newsContent) tags = [] for k, v in result: if v >= 5: tags.append(k) newsDict={ "id": helper.generateId(), "title":news["title"], "content":newsContent, "summary":newsContent, "length":length, "publish_time":helper.parseTime((news["time"][0:10])), "archive_time":datetime.datetime.now(), "author":news["url"], "channel":news["src"], "source":"JiSuShuJu", "hot_value":0, "category":[{"key":category.strip('\n'),"value":1}], "tag":tags, "position_city":None, "position_province":None } nd = NewsDocument(newsDict) isExsit = nd.findByTitle(); if isExsit: return else: nd.save() count+=1 page += 1 except Exception as ex: errorMessage=datetime.datetime.now().strftime("%m/%d/%Y %H:%M:%S ") errorMessage+= category+"-No."+str(count) #errorMessage+=" error:"+ex.message print(errorMessage) if not os.path.exists("tempfile"): os.makedirs("tempfile") f = codecs.open('tempfile/JiSuErrorLog.log', "a", "utf-8") f.write(errorMessage) f.close()
def test_parseTime(self): print('---> Test on parseTime') thisTime = parseTime( 'NC_H08_20200101_0000_L2CLP010_FLDK.02401_02401.nc', ft='CLP', pLe='L2') self.assertEqual(thisTime, dt.datetime(2020, 1, 1, 0, 0, 0))
def status(): cursor.execute("SELECT * FROM status") task = cursor.fetchone() if not task: print( "There is no task running. Use horologium start to start a task.") else: timepassed = time.time() - task[0] print("You're working on " + helper.parseTask(task) + "for" + helper.parseTime(timepassed))
def stop(): cursor.execute("SELECT * FROM status") task = cursor.fetchone() if not task: print( "There is no task running. Use horologium start to start a task.") else: timepassed = time.time() - task[0] cursor.execute("INSERT INTO history VALUES (?,?,?,?)", (task[0], task[1], task[2], timepassed)) db.commit() cursor.execute("DELETE FROM status WHERE 1=1") db.commit() print("Stopped time for " + helper.parseTask(task) + " after" + helper.parseTime(timepassed))
def report(): if args.days and not (args.label or args.task): cursor.execute("SELECT total(time) FROM history WHERE date > ?", [str(helper.timeDaysAgo(args.days))]) worktime = cursor.fetchone()[0] print("You worked in total for" + helper.parseTime(worktime) + " in the last {} days".format(args.days)) cursor.execute("SELECT DISTINCT label FROM history WHERE date > ?", [str(helper.timeDaysAgo(args.days))]) labels = cursor.fetchall() for label in labels: if label[0] is not None: cursor.execute( "SELECT total(time) FROM HISTORY WHERE label= ? AND date > ?", (str(label[0]), str(helper.timeDaysAgo(args.days)))) worktime = cursor.fetchone()[0] print(("[{}]\t:".format(label[0])) + helper.parseTime(worktime) if len(label[0]) > 5 else ("[{}]\t\t:".format(label[0])) + helper.parseTime(worktime)) if args.label and args.days and not args.task: cursor.execute( "SELECT total(time) FROM history WHERE label = ? AND date > ?", (args.label, helper.timeDaysAgo(args.days))) worktime = cursor.fetchone()[0] print("You worked in total for" + helper.parseTime(worktime) + " on [{}] in the last {} days".format(args.label, args.days)) cursor.execute( "SELECT DISTINCT task FROM history WHERE label = ? AND date > ?", (args.label, str(helper.timeDaysAgo(args.days)))) tasks = cursor.fetchall() for task in tasks: if task[0] is not None: cursor.execute( "SELECT total(time) FROM HISTORY WHERE task= ? AND date > ?", (str(task[0]), str(helper.timeDaysAgo(args.days)))) worktime = cursor.fetchone()[0] print(("{}\t:".format(task[0])) + helper.parseTime(worktime) if len(task[0]) > 5 else ("[{}]\t\t:".format(task[0])) + helper.parseTime(worktime)) if args.task and args.days and not args.label: cursor.execute( "SELECT total(time) FROM HISTORY WHERE task= ? AND date > ?", (str(args.task), str(helper.timeDaysAgo(args.days)))) worktime = cursor.fetchone()[0] print("You worked in total for {} on {} in the last {} days".format( helper.parseTime(worktime), args.task, args.days)) if args.task and args.label and args.days: cursor.execute( "SELECT total(time) FROM history WHERE label = ? AND task = ? AND date > ?", (args.label, args.task, helper.timeDaysAgo(args.days))) worktime = cursor.fetchone()[0] print( "You worked in total for {} on {} [{}] in the last {} days".format( helper.parseTime(worktime), args.task, args.label, args.days)) if args.task and args.label and not args.days: cursor.execute( "SELECT total(time) FROM history WHERE label = ? AND task = ?", (args.label, args.task)) worktime = cursor.fetchone()[0] print("You worked in total for {} on {} [{}]".format( helper.parseTime(worktime), args.task, args.label)) if args.label and not args.task and not args.days: cursor.execute("SELECT total(time) FROM history WHERE label = ?", (args.label, )) worktime = cursor.fetchone()[0] print("You worked in total for" + helper.parseTime(worktime) + " on [{}]".format(args.label)) cursor.execute("SELECT DISTINCT task FROM history WHERE label = ?", (args.label, )) tasks = cursor.fetchall() for task in tasks: if task[0] is not None: cursor.execute("SELECT total(time) FROM HISTORY WHERE task= ?", (str(task[0]), )) worktime = cursor.fetchone()[0] print(("{}\t:".format(task[0])) + helper.parseTime(worktime) if len(task[0]) > 5 else ("[{}]\t\t:".format(task[0])) + helper.parseTime(worktime)) if args.task and not args.days and not args.label: cursor.execute("SELECT total(time) FROM HISTORY WHERE task= ?", (str(args.task), )) worktime = cursor.fetchone()[0] print("You worked in total for {} on {}".format( helper.parseTime(worktime), args.task))