How to use get_date_str method in lisa

Best Python code snippet using lisa_python

BandB.py

Source:BandB.py Github

copy

Full Screen

...15 16def P_list(list):17 for i in list:18 P(i)19def get_date_str(arrstr,depstr):20 return ([int(i.strip()) for i in arrstr.split('/')],[int(i.strip()) for i in depstr.split('/')])21def get_dates(arrlist,deplist):22 return (date(arrlist[2],arrlist[0],arrlist[1]),date(deplist[2],deplist[0],deplist[1]))23def SAFE_write(file,str):24 if file:25 file.write(str)26def separate_reservation(beds,start,end):27 temp1=[[start,end]]28 temp2=[]29 count=030 flag=False31 for k,v in beds.items():32 flag=True33 temp3=[]34 templist=sorted(v,key=lambda x:cmpRL(x.arrive))35 while count<len(temp1):36 for i in range(len(templist)):37 arr,dep=get_dates(*get_date_str(templist[i].arrive,templist[i].depart))38 if temp1[count][0]<arr and temp1[count][1]>dep and temp1[count][0]<dep and temp1[count][1]>arr:39 if i==len(templist)-1:40 temp2+=[[k,dep,temp1[count][1]]]41 temp2+=[[k,temp1[count][0],arr]]42 temp3+=[[arr,dep]]43 break44 else:45 temp2+=[[k,temp1[count][0],arr]]46 temp3+=[[arr,dep]]47 temp1[count:count+1]=[[dep,temp1[count][1]]]48 elif temp1[count][0]<dep and temp1[count][1]<=dep and temp1[count][0]<arr and temp1[count][1]>arr:49 temp2+=[[k,temp1[count][0],arr]]50 temp3+=[[arr,temp1[count][1]]]51 break52 elif temp1[count][0]>=arr and temp1[count][1]>arr and temp1[count][0]<dep and temp1[count][1]<=dep:53 temp3+=[temp1[count]]54 break55 elif temp1[count][0]>=arr and temp1[count][1]>arr and temp1[count][0]<dep and temp1[count][1]>dep:56 temp3+=[[temp1[count][0],dep]]57 temp1[count:count+1]=[[dep,temp1[count][1]]]58 elif temp1[count][1]<=arr:59 temp2+=[[k,temp1[count][0],temp1[count][1]]]60 break61 count+=1 62 temp1+=temp363 if len(temp3):64 flag=False65 if flag:66 return temp267 else:68 return None69 70 71def Room_select(room,start,end):72 for i in room:73 arr2,dep2=get_dates(*get_date_str(i.arrive,i.depart))74 if start<dep2 and end>arr2:75 return False76 return True77 78def cmpRL(x):79 arrives=[int(i.strip()) for i in x.split('/')]80 arr=date(arrives[2],arrives[0],arrives[1])81 return arr82count_for_reservation=083rescount=084Beds={}85def Anteater_Bed_and_Breakfast(infile,outfile):86 global count_for_reservation,rescount,Beds87 if infile:88 for line in infile:89 command=line.strip()[:2].upper()90 text=line.strip()[2:].strip()91 if command=='NB':92 if Beds.get(text)!=None:93 SAFE_write(outfile,"Sorry, can't add room {:} again; it's already on the list.\n".format(text))94 else:95 Beds[text]=[]96 elif command=='LB':97 SAFE_write(outfile,'Number of bedrooms in service: {:}\n'.format(len(Beds)))98 SAFE_write(outfile,'------------------------------------\n')99 for k in sorted(Beds.keys(),key=lambda x:int(x)):100 SAFE_write(outfile,k+'\n')101 elif command=='PL':102 SAFE_write(outfile,text+'\n')103 elif command=='BD':104 flag=True105 for k,v in Beds.items():106 if k==text:107 del Beds[k]108 flag=False109 break110 if flag:111 SAFE_write(outfile,"Sorry, can't delete room {:}; it is not in service now\n".format(text))112 elif command=='NR':113 text=text.split(maxsplit=3)114 if text[0] in Beds:115 arr,dep=get_dates(*get_date_str(text[1],text[2]))116 if arr>=dep:117 SAFE_write(outfile,"Sorry, can't reserve room {:} ({:} to {:});\n ".format(text[0],text[1],text[2])+("can't leave before you arrive.\n" if arr>dep else "can't arrive and leave on the same day.\n"))118 else:119 flag=False120 if Beds.get(text[0]):121 for j in Beds[text[0]]:122 arr2,dep2=get_dates(*get_date_str(j.arrive,j.depart))123 if arr<dep2 and dep>arr2:124 flag=True125 break126 if flag is False:127 count_for_reservation+=1128 rescount+=1129 Beds[text[0]].append(Reservation(count_for_reservation,text[1],text[2],text[3]))130 SAFE_write(outfile,'Reserving room {:} for {:} -- Confirmation #{:}\n (arriving {:}, departing {:})\n'.format(text[0],text[3],count_for_reservation,text[1],text[2]))131 else:132 flag2=False133 key2=0134 for k,v in Beds.items():135 flag2=Room_select(v,arr,dep)136 if flag2:137 key2=k138 break139 if flag2:140 count_for_reservation+=1141 rescount+=1142 Beds[key2].append(Reservation(count_for_reservation,text[1],text[2],text[3]))143 SAFE_write(outfile,'Reserving room {:} (move to {:}) for {:} -- Confirmation #{:}\n (arriving {:}, departing {:})\n'.format(text[0],key2,text[3],count_for_reservation,text[1],text[2]))144 else:145 #several rooms reversation146 sep=separate_reservation(Beds,arr,dep)147 if sep:148 for i in sep:149 count_for_reservation+=1150 rescount+=1151 res=Reservation(count_for_reservation,'{:2d}/{:2d}/{:4d}'.format(*[int(c) for c in i[1].strftime('%m/%d/%Y').split('/')]),'{:2d}/{:2d}/{:4d}'.format(*[int(c) for c in i[2].strftime('%m/%d/%Y').split('/')]),text[3])152 Beds[i[0]].append(res)153 SAFE_write(outfile,'Reserving room {:} for {:} -- Confirmation #{:}\n (arriving {:}, departing {:})\n'.format(i[0],text[3],res.ID,res.arrive,res.depart))154 else:155 SAFE_write(outfile,"Sorry, can't reserve room {:} ({:} to {:})\n".format(text[0],text[1],text[2])) 156 else:157 SAFE_write(outfile,"Sorry; can't reserve room {:}; room not in service\n".format(text[0]))158 elif command=='LR':159 SAFE_write(outfile,'Number of reservations: {:}\nNo. Rm. Arrive Depart Guest\n------------------------------------------------\n'.format(rescount))160 '''161 for i in range(count_for_reservation):162 for k,v in Beds.items():163 for j in v:164 if j.ID==i+1:165 arrives=j.arrive.split('/')166 departs=j.depart.split('/')167 SAFE_write(outfile,'{:3d} {:} {:2d}/{:2d}/{:4d} {:2d}/{:2d}/{:4d} {:20s}\n'.format(i+1,k,int(arrives[0]),int(arrives[1]),int(arrives[2]),int(departs[0]),int(departs[1]),int(departs[2]),j.guest))168 '''169 result=[]170 for k,v in Beds.items():171 for i in v:172 result.append([k,i])173 for j in sorted(result,key=lambda x:cmpRL(x[1].arrive)):174 arrives,departs=get_date_str(j[1].arrive,j[1].depart)175 SAFE_write(outfile,'{:3d} {:} {:2d}/{:2d}/{:4d} {:2d}/{:2d}/{:4d} {:20s}\n'.format(*[j[1].ID,j[0],*arrives,*departs,j[1].guest]))176 elif command=='RR':177 flag=False178 num=int(text)179 for k,v in Beds.items():180 for i in range(len(v)):181 if v[i].ID==num:182 del v[i]183 rescount-=1184 flag=True185 break186 if flag:187 break188 if not flag:189 SAFE_write(outfile,"Sorry, can't cancel reservation; no confirmation number {:}\n".format(text))190 elif command=='RB':191 flag=False192 for i in Beds.keys():193 if i==text:194 rescount-=len(Beds[i])195 for j in Beds[i]:196 SAFE_write(outfile,"Deleting room {:} forces cancellation of this reservation:\n {:} arriving {:} and departing {:} (Conf. #{:})\n".format(text,j.guest,j.arrive,j.depart,j.ID))197 del Beds[i]198 flag=True199 break200 if not flag:201 SAFE_write(outfile,"Sorry, can't delete room {:}; it is not in service now\n".format(text))202 elif command=='RD':203 flag=True204 for k,v in Beds.items():205 for j in v:206 if j.ID==int(text):207 flag=False208 del Beds[k]209 rescount-=1210 break211 if flag is False:212 break 213 if flag:214 SAFE_write(outfile,"Sorry, can't cancel reservation; no confirmation number {:}\n".format(text))215 elif command=='BR':216 if Beds.get(text):217 SAFE_write(outfile,'Reservations for room {:}:\n'.format(text))218 for i in Beds[text]:219 arrives,departs=get_date_str(i.arrive,i.depart)220 SAFE_write(outfile,' {:2d}/{:2d}/{:4d} to {:2d}/{:2d}/{:4d}: {:}\n'.format(*[*arrives,*departs,i.guest]))221 else:222 SAFE_write(outfile,"Sorry, can't search room {:}; it is not in service now\n".format(text))223 elif command=='RG':224 SAFE_write(outfile,'Reservations for {:}:\n'.format(text))225 for k,v in Beds.items():226 for i in v:227 if i.guest==text:228 arrives,departs=get_date_str(i.arrive,i.depart)229 SAFE_write(outfile,' {:2d}/{:2d}/{:4d} to {:2d}/{:2d}/{:4d}: room {:}\n'.format(*[*arrives,*departs,k]))230 elif command=='LA':231 SAFE_write(outfile,'Guests arriving on {:}:\n'.format(text))232 for k,v in Beds.items():233 for i in v:234 if i.arrive==text:235 SAFE_write(outfile,' {:} (room {:})\n'.format(i.guest,k))236 elif command=='LD':237 SAFE_write(outfile,'Guests departing on {:}:\n'.format(text))238 for k,v in Beds.items():239 for i in v:240 if i.depart==text:241 SAFE_write(outfile,' {:} (room {:})\n'.format(i.guest,k))242 elif command=='LF':243 dates=text.split()244 arr,dep=get_dates(*get_date_str(dates[0],dates[1]))245 SAFE_write(outfile,'Bedrooms free between {:} to {:}:\n'.format(dates[0],dates[1]))246 for k,v in Beds.items():247 flag=False248 for j in v:249 arr2,dep2=get_dates(*get_date_str(j.arrive,j.depart))250 if arr<dep2 and dep>arr2:251 flag=True252 break253 if flag is False:254 SAFE_write(outfile,' {:}\n'.format(k))255 elif command=='LO':256 dates=text.split()257 arr,dep=get_dates(*get_date_str(dates[0],dates[1]))258 SAFE_write(outfile,'Bedrooms free between {:} to {:}:\n'.format(dates[0],dates[1]))259 for k,v in Beds.items():260 flag=True261 for j in v:262 arr2,dep2=get_dates(*get_date_str(j.arrive,j.depart))263 if arr<dep2 and dep>arr2:264 flag=False265 break266 if flag is False:267 SAFE_write(outfile,' {:}\n'.format(k))268 if outfile:269 savefile=open('save.txt','w')270 for i in Beds.keys():271 savefile.write('NB {:}\n'.format(i))272 for k,v in Beds.items():273 for j in v:274 arrives,departs=get_date_str(j.arrive,j.depart)275 savefile.write('NR {:} {:d}/{:d}/{:d} {:d}/{:d}/{:d} {:}\n'.format(*[k,*arrives,*departs,j.guest]))276 savefile.close()277 outfile.close()278 infile.close()279try:280 savefile=open('save.txt')281except:282 savefile=None283Anteater_Bed_and_Breakfast(savefile,None)284infile=open(input('What to input '))285outfile=open(input('What to output '),'w')286Anteater_Bed_and_Breakfast(infile,outfile)287'---------------------------------------------------------'288'Here is the console version of Anteater_Bed_and_Breakfast'289'---------------------------------------------------------'290def CONSOLE_Anteater_Bed_and_Breakfast():291 helptext=\292 '''293Please use one of these commands below:294NB (for "add a new bedroom") followed by an integer room number (in the range 1–999). Add a new bedroom with the specified room number.295LB (for "list bedrooms"). Print a list of the bedrooms currently available. 296PL (for "print line"), followed by any text. Simply print (or "echo") a line, 297## Comment, followed by any text.298NR (followed by a bedroom number, then an arrival date in the form mm/dd/yyyy, then a departure date in the form mm/dd/yyyy, then the guest's name): Add a new reservation for the specified room on the specified dates.299LR (for "list reservations"). Print all the reservations.300RR (for "remove reservation"), followed by the confirmation number of a reservation. Deletes the specified reservation.301BR (for "bedroom reservations"), followed by a number. Lists all reservations for a given bedroom.302RG (for "reservations by guest"), followed by a string. List all reservations for a given guest.303LA (for "list arrivals"), followed by a date in the same mm/dd/yyyy form as before. Print a list of all guests arriving on the specified date.304LD (for "list departures"), followed by a date in the same mm/dd/yy form as before. Print a list of all guests departing on the specified date.305LF (for "list free bedrooms"), followed by two dates. List all bedrooms that are free each night for a guest arriving on the first date and departing on the second.306LO (for "list occupied bedrooms"), followed by two dates. List all bedrooms that are occupied for at least one night between the given arrival and departure dates.307QU just quit the program308 '''309 global count_for_reservation,rescount,Beds310 print(helptext)311 while True:312 line=input()313 command=line.strip()[:2].upper()314 text=line.strip()[2:].strip()315 if command=='NB':316 if Beds.get(text)!=None:317 print("Sorry, can't add room {:} again; it's already on the list.\n".format(text),end='')318 else:319 Beds[text]=[]320 elif command=='LB':321 print('Number of bedrooms in service: {:}\n'.format(len(Beds)),end='')322 print('------------------------------------')323 for k in sorted(Beds.keys(),key=lambda x:int(x)):324 print(k)325 elif command=='PL':326 print(text)327 elif command=='BD':328 flag=True329 for k,v in Beds.items():330 if k==text:331 del Beds[k]332 flag=False333 break334 if flag:335 print("Sorry, can't delete room {:}; it is not in service now\n".format(text),end='')336 elif command=='NR':337 text=text.split(maxsplit=3)338 if text[0] in Beds:339 arr,dep=get_dates(*get_date_str(text[1],text[2]))340 if arr>=dep:341 print("Sorry, can't reserve room {:} ({:} to {:});\n ".format(text[0],text[1],text[2])+("can't leave before you arrive.\n" if arr>dep else "can't arrive and leave on the same day.\n"),end='')342 else:343 flag=False344 if Beds.get(text[0]):345 for j in Beds[text[0]]:346 arr2,dep2=get_dates(*get_date_str(j.arrive,j.depart))347 if arr<dep2 and dep>arr2:348 flag=True349 break350 if flag is False:351 count_for_reservation+=1352 rescount+=1353 Beds[text[0]].append(Reservation(count_for_reservation,text[1],text[2],text[3]))354 print('Reserving room {:} for {:} -- Confirmation #{:}\n (arriving {:}, departing {:})\n'.format(text[0],text[3],count_for_reservation,text[1],text[2]),end='')355 else:356 flag2=False357 key2=0358 for k,v in Beds.items():359 flag2=Room_select(v,arr,dep)360 if flag2:361 key2=k362 break363 if flag2:364 count_for_reservation+=1365 rescount+=1366 Beds[key2].append(Reservation(count_for_reservation,text[1],text[2],text[3]))367 print('Reserving room {:} (move to {:}) for {:} -- Confirmation #{:}\n (arriving {:}, departing {:})\n'.format(text[0],key2,text[3],count_for_reservation,text[1],text[2]),end='')368 else:369 #several rooms reversation370 sep=separate_reservation(Beds,arr,dep)371 if sep:372 for i in sep:373 count_for_reservation+=1374 rescount+=1375 res=Reservation(count_for_reservation,'{:2d}/{:2d}/{:4d}'.format(*[int(c) for c in i[1].strftime('%m/%d/%Y').split('/')]),'{:2d}/{:2d}/{:4d}'.format(*[int(c) for c in i[2].strftime('%m/%d/%Y').split('/')]),text[3])376 Beds[i[0]].append(res)377 print('Reserving room {:} for {:} -- Confirmation #{:}\n (arriving {:}, departing {:})\n'.format(i[0],text[3],res.ID,res.arrive,res.depart),end='')378 else:379 print("Sorry, can't reserve room {:} ({:} to {:})\n".format(text[0],text[1],text[2]),end='') 380 else:381 print("Sorry; can't reserve room {:}; room not in service\n".format(text[0]),end='')382 elif command=='LR':383 print('Number of reservations: {:}\nNo. Rm. Arrive Depart Guest\n------------------------------------------------\n'.format(rescount),end='')384 result=[]385 for k,v in Beds.items():386 for i in v:387 result.append([k,i])388 for j in sorted(result,key=lambda x:cmpRL(x[1].arrive)):389 arrives,departs=get_date_str(j[1].arrive,j[1].depart)390 print('{:3d} {:} {:2d}/{:2d}/{:4d} {:2d}/{:2d}/{:4d} {:20s}\n'.format(*[j[1].ID,j[0],*arrives,*departs,j[1].guest]),end='')391 elif command=='RR':392 flag=False393 num=int(text)394 for k,v in Beds.items():395 for i in range(len(v)):396 if v[i].ID==num:397 del v[i]398 rescount-=1399 flag=True400 break401 if flag:402 break403 if not flag:404 print("Sorry, can't cancel reservation; no confirmation number {:}\n".format(text),end='')405 elif command=='RB':406 flag=False407 for i in Beds.keys():408 if i==text:409 rescount-=len(Beds[i])410 for j in Beds[i]:411 print("Deleting room {:} forces cancellation of this reservation:\n {:} arriving {:} and departing {:} (Conf. #{:})\n".format(text,j.guest,j.arrive,j.depart,j.ID),end='')412 del Beds[i]413 flag=True414 break415 if not flag:416 print("Sorry, can't delete room {:}; it is not in service now\n".format(text),end='')417 elif command=='RD':418 flag=True419 for k,v in Beds.items():420 for j in v:421 if j.ID==int(text):422 flag=False423 del Beds[k]424 rescount-=1425 break426 if flag is False:427 break 428 if flag:429 print("Sorry, can't cancel reservation; no confirmation number {:}\n".format(text),end='')430 elif command=='BR':431 if Beds.get(text):432 print('Reservations for room {:}:\n'.format(text),end='')433 for i in Beds[text]:434 arrives,departs=get_date_str(i.arrive,i.depart)435 print(' {:2d}/{:2d}/{:4d} to {:2d}/{:2d}/{:4d}: {:}\n'.format(*[*arrives,*departs,i.guest]),end='')436 else:437 print("Sorry, can't search room {:}; it is not in service now\n".format(text),end='')438 elif command=='RG':439 print('Reservations for {:}:\n'.format(text),end='')440 for k,v in Beds.items():441 for i in v:442 if i.guest==text:443 arrives,departs=get_date_str(i.arrive,i.depart)444 print(' {:2d}/{:2d}/{:4d} to {:2d}/{:2d}/{:4d}: room {:}\n'.format(*[*arrives,*departs,k]),end='')445 elif command=='LA':446 print('Guests arriving on {:}:\n'.format(text),end='')447 for k,v in Beds.items():448 for i in v:449 if i.arrive==text:450 print(' {:} (room {:})\n'.format(i.guest,k),end='')451 elif command=='LD':452 print('Guests departing on {:}:\n'.format(text),end='')453 for k,v in Beds.items():454 for i in v:455 if i.depart==text:456 print(' {:} (room {:})\n'.format(i.guest,k),end='')457 elif command=='LF':458 dates=text.split()459 arr,dep=get_dates(*get_date_str(dates[0],dates[1]))460 print('Bedrooms free between {:} to {:}:\n'.format(dates[0],dates[1]),end='')461 for k,v in Beds.items():462 flag=False463 for j in v:464 arr2,dep2=get_dates(*get_date_str(j.arrive,j.depart))465 if arr<dep2 and dep>arr2:466 flag=True467 break468 if flag is False:469 print(' {:}\n'.format(k),end='')470 elif command=='LO':471 dates=text.split()472 arr,dep=get_dates(*get_date_str(dates[0],dates[1]))473 print('Bedrooms free between {:} to {:}:\n'.format(dates[0],dates[1]),end='')474 for k,v in Beds.items():475 flag=True476 for j in v:477 arr2,dep2=get_dates(*get_date_str(j.arrive,j.depart))478 if arr<dep2 and dep>arr2:479 flag=False480 break481 if flag is False:482 print(' {:}\n'.format(k),end='')483 elif command=='QU':484 break485 elif command=='##':486 pass487 else:488 print("'{:}' is not a vaild command, please check the command again".format(command))489 print('saving....')490 savefile=open('save.txt','w')491 for i in Beds.keys():492 savefile.write('NB {:}\n'.format(i))493 for k,v in Beds.items():494 for j in v:495 arrives,departs=get_date_str(j.arrive,j.depart)496 savefile.write('NR {:} {:d}/{:d}/{:d} {:d}/{:d}/{:d} {:}\n'.format(*[k,*arrives,*departs,j.guest]))497 savefile.close()498 print('saving complete')499 print('thanks for using the console version of this program!')500 ...

Full Screen

Full Screen

core.py

Source:core.py Github

copy

Full Screen

...19 return [post.url]20 return list(set([''.join(m) for m in re.findall(yt_link_pattern, post.selftext_html)]))21def get_now_plus_utc_offset():22 return int(time.time()) + utc_offset23def get_date_str(timestamp, is_utc_needed):24 if is_utc_needed:25 return datetime.utcfromtimestamp(timestamp).replace(tzinfo=pytz.utc).strftime(timestamp_date_format) + ' UTC'26 else:27 return datetime.utcfromtimestamp(timestamp).strftime(timestamp_date_format) + ' L_TZ'28def print_post(post):29 print('Title:', post[0])30 print('Name:', post[1])31 print('Score:', post[2])32 print('Ups:', post[3])33 print('Downs:', post[4])34 print('Author username:', post[5])35 print('Date UTC:', get_date_str(post[6], True))36 print('Text content:', post[7])37 for i, link in enumerate(post[8]):38 print('Link', str(i + 1) + ':', link)39 print('Permaink:', post[-1])40def clear_str(s):41 r = ''42 for ss in s:43 if ss.isalnum() or ss in '[]_,.;+=/*-+)(*&^%$#@!~`{}""':44 r += ss45 else:46 r += ' '47 return r48def get_archive_name(subreddit_name):49 return archives_folder + 'yt_posts_from_' + subreddit_name + '.csv'50def save_posts_to_csv(yt_posts, subreddit_name, start_timestamp):51 latest_timestamp = 052 with open(get_archive_name(subreddit_name), 'w', newline='') as csvfile:53 rowwriter = csv.writer(csvfile, delimiter='\t', quotechar='\t', quoting=csv.QUOTE_NONE)54 rowwriter.writerow(['Title', 'Name', 'Score', 'Ups', 'Downs', 'Username', 'Date', 'Plain text', 'Links', 'Permalink'])55 for post in yt_posts:56 row = list(post)57 row[8] = ','.join(post[8])58 row[0] = clear_str(post[0])59 row[7] = clear_str(post[7])60 if row[6] > latest_timestamp:61 latest_timestamp = row[6]62 rowwriter.writerow(row)63 csvfile.write(str(start_timestamp) + '_' + str(latest_timestamp) + '\r\n')64 csvfile.write(str(int(time.time())))65def load_posts_from_csv(subreddit_name):66 start_end_timestamps = [0, 0]67 last_update_timestamp = 068 posts = []69 filename = get_archive_name(subreddit_name)70 try:71 with open(filename, 'r', newline='') as csvfile:72 rowreader = csv.reader(csvfile, delimiter='\t', quotechar='\t', quoting=csv.QUOTE_NONE)73 rowreader.__next__()#skip column names74 for row in rowreader:75 if len(row) > 1:76 post = list(row)77 for ii in [2, 3, 4, 6]:78 post[ii] = int(row[ii])79 post[8] = post[8].split(',')80 posts.append(post)81 else:82 start_end_timestamps = [int(s) for s in row[0].split('_')]83 break84 last_update_timestamp = int(rowreader.__next__()[0])85 except (OSError, IOError) as e:86 print('Error occured while trying accessing', filename)87 print('Creating new file', filename)88 print()89 with open(filename, 'w', newline='') as csvfile:90 csvfile.write('0_0\n')91 csvfile.write(str(int(time.time())))92 return posts, start_end_timestamps, last_update_timestamp93def get_yt_posts_and_permalinks_set_between(r, subreddit_name, already_archived_permalinks_set, start_timestamp, end_timestamp):94 posts = get_posts_between(r, subreddit_name, start_timestamp, end_timestamp)#generator95 new_yt_posts = []96 new_permalinks_set = set()97 for post in posts:98 permalink = post.permalink.replace('?ref=search_posts','')99 if permalink not in already_archived_permalinks_set and permalink not in new_permalinks_set:100 yt_links = get_yt_links(post)101 if len(yt_links) > 0:102 new_yt_posts.append((post.title, post.name, post.ups - post.downs, post.ups, post.downs, post.author.name, int(post.created_utc), post.selftext, yt_links, permalink))103 new_permalinks_set.add(permalink)104 return new_yt_posts, new_permalinks_set105def update_subreddit_archive(r, subreddit_name, search_granularity_interval=day_in_seconds, repeat_search_times=3):106 yt_posts, start_end_timestamps, last_update_timestamp = load_posts_from_csv(subreddit_name)107 permalinks_set = set([post[-1] for post in yt_posts])108 print('Database has {0} posts total. Range from {1} to {2}'.format(len(yt_posts), get_date_str(start_end_timestamps[0], True), get_date_str(start_end_timestamps[1], True)))109 print('Last update was', get_date_str(last_update_timestamp, False))110 if start_end_timestamps[0] == start_end_timestamps[1] == 0:111 start_timestamp = input('\nPlease enter date from which to start gathering posts. Format ' + timestamp_date_format +112 '\nExample: ' + get_date_str(time.time(), False) + '\n')113 start_end_timestamps[0] = datetime.strptime(start_timestamp, timestamp_date_format).replace(tzinfo=pytz.utc).timestamp()114 else:115 #start_end_timestamps[0] = max(start_end_timestamps[1] - search_granularity_interval, start_end_timestamps[0])116 start_end_timestamps[0] = max(last_update_timestamp - search_granularity_interval, start_end_timestamps[0])117 start_end_timestamps[1] = get_now_plus_utc_offset()118 start_end_timestamps[0] = int(start_end_timestamps[0])119 #start_end_timestamps[1] = int(math.ceil((start_end_timestamps[1] - start_end_timestamps[0])/search_granularity_interval)*search_granularity_interval) + start_end_timestamps[0]120 print('Current search granularity interval is', str(timedelta(seconds=search_granularity_interval)))121 print()122 print(int(math.ceil((start_end_timestamps[1] - start_end_timestamps[0])/search_granularity_interval)), 'intervals to search')123 for current_search_timestamp_step in range(start_end_timestamps[0], start_end_timestamps[1], search_granularity_interval):124 start = current_search_timestamp_step125 end = current_search_timestamp_step + search_granularity_interval126 print('Getting posts between', get_date_str(start, True), 'and', get_date_str(end, True))127 got_posts = 0128 for i in range(repeat_search_times):129 new_yt_posts, new_permalinks_set = get_yt_posts_and_permalinks_set_between(r, subreddit_name, permalinks_set, start, end)130 got_posts += len(new_yt_posts)131 yt_posts.extend(new_yt_posts)132 permalinks_set.update(new_permalinks_set)133 end += 1#to prevent praw from caching134 print('Got', got_posts, 'new posts containing youtube links')135 """136 gets random results each time137 counts = []138 start = 1474761600139 end = 1474848000140 for i in range(30):141 end += 1142 print('Getting posts between', get_date_str(start, True), 'and', get_date_str(end, True))143 new_yt_posts, new_permalinks_set = get_yt_posts_and_permalinks_set_between(r, subreddit_name, permalinks_set, start, end)144 counts.append(len(new_yt_posts))145 print('Got', len(new_yt_posts), 'new posts containing youtube links')146 print(len(counts))147 print(counts)148 print('14', len([c for c in counts if c == 14]))149 print('15', len([c for c in counts if c == 15]))150 """151 save_posts_to_csv(yt_posts, subreddit_name, start_end_timestamps[0])...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...25import sys26import url27from .misc import *28from .logger import *29# log.init_logger('~/temp/log/log_' + get_date_str() + '.log')30def exit(code = 0):31 sys.exit(0)32 33is_main = mod.is_main34init_logger = log.init_logger35def sit(img, path = None, name = ""):36 if path is None:37 _count = get_count();38 path = '~/temp/no-use/images/%s_%d_%s.jpg'%(log.get_date_str(), _count, name)39 40 if type(img) == list:41 plt.show_images(images = img, path = path, show = False, axis_off = True, save = True)42 else:43 plt.imwrite(path, img)44 45 return path46_count = 0;47def get_count():48 global _count;49 _count += 1;50 return _count 51def cit(img, path = None, rgb = True, name = ""):52 _count = get_count();53 if path is None:54 img = np.np.asarray(img, dtype = np.np.uint8)55 path = '~/temp/no-use/%s_%d_%s.jpg'%(log.get_date_str(), _count, name)56 _img.imwrite(path, img, rgb = rgb)57 return path 58def argv(index):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful