def __init__(self): ''' Constructor ''' self.week = {} # self.fill_week() for i in range(5): day = timenode([time(7, 0), time(22, 0)]) self.week[i + 1] = day self.courses = set() self.count = 0 self.credit = 0
def __init__(self, title, length=None, year=0): self.title = title if length == None: self.length = mytime.time() else: self.length = length self.year = year
def process_time(t): tags_dict = dict() a = t.replace("\xa0", " ") w = a.find(" ") tags_dict["days"] = a[:w] a = a[w + 1:] ti = a[:a.find(" ")] middle = a.find("-") bt = a[:middle] et = a[middle + 1:] if "PM" in bt: tags_dict["b_t"] = time(int(bt[:2]) + 12, int(bt[3:5])) else: tags_dict["b_t"] = time(int(bt[:2]) + 12, int(bt[3:5])) if "PM" in et: tags_dict["e_t"] = time(int(et[:2]) + 12, int(et[3:5])) else: tags_dict["e_t"] = time(int(et[:2]) + 12, int(et[3:5])) return tags_dict
def timing_monthly_run(day_in_months: list, function, *args): days = [] # 存放转换成时间戳的day_in_months datetime_run = 0 # 下一个要运行的时间 for day_in_month in day_in_months: days.append( mytime.mktime(mytime.strptime(day_in_month, "%Y-%m-%d %H:%M:%S"))) while True: current_time = mytime.time() for i in range(len(day_in_months)): if current_time == days[i]: datetime_run = current_time + 1 # 推迟1秒 elif days[1] < current_time < days[i + 1]: datetime_run = days[i + 1] + 1 # 推迟1秒 else: pass while mytime.time() < datetime_run: mytime.sleep(1) else: function(*args)
def __init__(self, bt, et, days, res, ures, wait, t, title, course_id, class_id, credit=0, instructor="Unknown", classroom="TBA", type="Unknown", recitation=False): ''' Constructor ''' self.b_t = time(bt[0], bt[1]) self.e_t = time(et[0], et[1]) self.res = int(res) self.ures = int(ures) self.wait = int(wait) self.type = str(t) self.days = set() self.process_days(days) self.b_g = self.b_t - 15 self.e_g = self.b_t + 15 self.class_id = class_id self.course_id = course_id self.credit = credit self.instructor = instructor self.classroom = classroom self.type = type self.recitation = recitation self.title = title self.t = t
def process_class(tbody): trs = tbody.find_all("tr") # tags = [] tags_dict = dict() tds = trs[0].find_all("td") t = tds[0].get_text() print(t) tags_dict["course_id"] = str(t) t = tds[1].get_text() print(t) tags_dict["title"] = str(t) t = tds[3].get_text() print(t) tags_dict["credit"] = int(t[0]) trs.pop(0) for tr in trs: tds = tr.find_all("td") t = tds[0].get_text() print(type(t)) print(t) tags_dict["class_id"] = t t = tds[1].get_text() print(t) tags_dict["type"] = t t = tds[2].get_text() print(t) try: tags_dict = dict(list(process_time(t).items()) + list(tags_dict.items())) except: print("failed to convert to object" + str(tags_dict)) t = tds[3].get_text() print(t) t = tds[4].get_text() print(t) t = tds[5].get_text() print(t) t = tds[6].get_text() print(t) t = tds[7].get_text() print(t) s = tds[8].get_text()[13:] try: tags_dict["res"] = int(t[s:]) except: tags_dict["res"] = 0 if not "res" in tags_dict: tags_dict["res"] = 0 try : c = PittClass( time(12, 40), # bt time(20, 10), # et "We", # days tags_dict["res"], 0, # ures 0, # wait "A&S", # t tags_dict["title"], # title tags_dict["course_id"], # course_id tags_dict["class_id"], # class_id tags_dict["credit"] ) # credit print(c) except: print("failed to convert to object" + str(tags_dict))
print(num_16) ss = str_16.decode('hex') # 16进制串转字符串 print(ss) # IP地址匹配 import re ipbook = "00044931.22.22.11_111d.df5.fd.d223.211.222.11111.44f.33.22.33aff333.32.22.__33931..22.22.11931.22333.22.11" IP = re.findall("\d{1,3}(?:\.\d{1,3}){3}", ipbook) IP2 = re.findall("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", ipbook) IP3 = re.findall("(?:\d{1,3}\.){3}\d{1,3}", ipbook) IP4 = re.findall("\d+(?:\.+\d+){1,3}", ipbook) print(IP) print(IP2) print(IP3) print(IP4) import mytime print(mytime.time()) # 时间戳 print(mytime.gmtime()) # 结构化 print(mytime.localtime()) # 结构化 print(mytime.strftime("%Y%m%d %H%M%S")) # 格式化 print(mytime.strftime("%Y-%m-%d %H:%M:%S")) # 格式化 print("") print(mytime.strptime("2019-05-16 15:06:33", "%Y-%m-%d %H:%M:%S")) # 格式化转成结构化 print(mytime.mktime(mytime.strptime("2019-05-16", "%Y-%m-%d"))) # 结构化转成时间戳 print(mytime.mktime(mytime.localtime())) # 结构化转成时间戳
def fill_week(self): for i in range(5): day = timenode([time(7, 0), time(22, 0)]) self.week[i + 1] = day