def get_menu(): """Checks if menu is current, if yes, load menu from file, if not, downloads data from internet and saves them to file, and updates last_updated""" d = {} if check_current(): with open("menu", "rb") as f: p = Unpickler(f) d = p.load() else: d = { "obed": get_menza_zizkov_obed(), "pizza": get_pizza(), "zdrava": get_zdrava(), "vecere": get_menza_zizkov_vecere(), "jarov": get_jarov(), "volha": get_volha() } # write new menu to file with open("menu", "wb") as f: f.truncate() p = Pickler(f, 0) p.dump(d) # update last_updated with open("last_updated", "wb") as f: f.truncate() p = Pickler(f, 0) p.dump(date.today().strftime("%w")) return d
def add_service(self,name,techno,outil): #ouverture en lecture binaire with open('portfolio/model/data', "rb") as fic: record = Unpickler(fic) liste = record.load() liste.append(Service(name,techno,outil)) # ouvreture en ecriture binaire with open('portfolio/model/data', "wb") as fic: record = Pickler(fic) record.dump(liste)
def delete_service(self,name): # ouverture en lecture binaire with open('portfolio/model/data', "rb") as fic: record = Unpickler(fic) liste = record.load() for el in liste: if el.name == name: liste.remove(el) break # ouvreture en ecriture binaire with open('portfolio/model/data', "wb") as fic: record = Pickler(fic) record.dump(liste)
if response.ok: soup = BeautifulSoup(response.content, 'html.parser') try: name = soup.find('div', {'class', 'content-recipe'}).find( 'h1', {'class', 'main-title'}).text categorie = 'Plat principal' ingredients = soup.find( 'ul', {'class', 'recipe-ingredients__list'}).find_all('li') ingredients = [ ingredient.find('div').text for ingredient in ingredients ] person_number = soup.find('div', {'class', 'recipe-infos__quantity'}).\ find('span', {'class', 'title-2'}).text image_link = soup.find('picture').find('img').get('src') preparation = soup.find( 'ol', {'class', 'recipe-preparation__list'}).find_all('li') preparation = [direction.text for direction in preparation] except AttributeError as e: lg.warning('Attribute error => {}'.format(e)) else: writte_on_file_recip(name, categorie, person_number, preparation, image_link, \ ingredients) links_to_scrap.remove(link) with open('new_links', 'wb') as fp: obj = Pickler(fp) obj.dump(links_to_scrap) recette += 1 print('Ajouté') print('Recette ajouté : {}'.format(recette))
if sup == b"s": system("cls") print("Sauvegardes existantes :\n", *toprt, "Entrez le nom de la sauvegarde \u00E0 supprimer : ", sep="\n") tormv = input() try: del (score_dict["cartes\\{}.txt".format(tormv)]) print( "Sauvegarde supprim\u00E9e avec succ\u00E8s.\n\nAppuyez sur n'importe quelle touche pour revenir au menu..." ) except KeyError: print( "Erreur - la sauvegarde {} n'exixte pas\n\nAppuyez sur n'importe quelle touche pour revenir au menu..." .format(tormv)) getch() elif play == b"\x1b": #quitter system("cls") print("Quitter le jeu ?\n", "0 - oui", "1 - non", sep="\n") quit_confirmation = getch() if quit_confirmation == b"0": quit_game = True with open("Données/save", "wb") as fichier: my = Pickler(fichier) my.dump(score_dict)
l = ldb.get(lname) for d in ddb.db: if (str(d.line) == str(lname)) and (d.station in l.dir1): x = d.time.hour*100+d.time.minute y = l.dir1.index(d.station) xA = [x] yA = [y] for dd in d.delays: v = int(dd[1][1:]) if v > 0: xA.append(x + v) yA.append(y) if len(xA) > 1: plt.plot(xA, yA, '-or') else: plt.plot(xA, yA, '-ob') plt.show() if writeUpdate: f = open("data.pickle","wb") p = Pickler(f, HIGHEST_PROTOCOL) p.dump(ddb) p.dump(ldb) p.dump(staMap) f.flush() f.close()