<commit_before>from CafeScraper.Scraper import Scraper
import json

scraper = Scraper()
json_dump = json.dumps(list(scraper.cafes_dict.values()), default=lambda c: c.__dict__, sort_keys=True)
print(json_dump)

# save to file
with open('menus.json', 'w') as fp:
    print(json_dump, file=fp)

#
#
# for cafe in scraper.cafes:
#     #print(cafe)
#     json_dump = json.dumps(cafe, default=lambda c: c.__dict__)
#     print(json_dump)<commit_msg>Backup all menus collected while keeping a main json file.<commit_after>from pathlib import Path
from time import time

from CafeScraper.Scraper import Scraper
import json

def collect_backup_and_dump():

    '''
    Get the new json
    '''
    scraper = Scraper()
    json_dump = json.dumps(list(scraper.cafes_dict.values()), default=lambda c: c.__dict__, sort_keys=True)

    '''
    Backup this json
    '''
    # check if backup folder exists
    BACKUP_PATH_NAME = "backup_menu_json"
    cwd = Path('.')
    if not (cwd / BACKUP_PATH_NAME).exists():
        # create it if it doesn't
        print("DEBUG: backup folder did not exist, creating now...")
        (cwd / BACKUP_PATH_NAME).mkdir(mode=0o744)

    # epoch time this new json was created in seconds rounded to the nearest integer
    new_backup_file_name = str(int(time())) + '_menus_save.json'
    absolute_path = str((cwd / BACKUP_PATH_NAME).absolute()) + '/' + new_backup_file_name
    with open(absolute_path, 'w') as fp:
        print(json_dump, file=fp)

    '''
    Distribute the new json
    '''
    with open('menus.json', 'w') as fp:
        print(json_dump, file=fp)

if __name__ == '__main__':
    collect_backup_and_dump()

{'fraction_non_alphanumeric': 0.11522633744855967, 'fraction_numerical': 0.0023515579071134627, 'mean_word_length': 3.1210653753026634, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1517234', 'n_tokens_mistral': 613, 'n_tokens_neox': 573, 'n_words': 146}