def process_reporting_data(data): # quick way to handle both .zip and .csv try: zip_file = ZipFileManager("downloaded.zip").write_content(data) report_csv = zip_file.read_first_file( ).return_content_as_stripped_string() except zipfile.BadZipFile as e: report_csv = Reader( data ).return_content_as_stripped_string_with_commas_within_quotes_removed( ) report_csv_file = FileManager("report.csv").write_content(report_csv) formatted_reporting_data = [ data.split(',') for data in Reader(report_csv).return_content_as_list() ] return formatted_reporting_data
def get_reporting_data(gmail_service, advertiser): api = GmailApi(gmail_service, advertiser.get_email_subject()) if advertiser.get_download_link(): email_body = api.get_latest_message_body() download_link = Reader(email_body).get_download_link( advertiser.get_download_link()) return requests.get(download_link).content reporting = api.get_latest_message_attachment() return reporting
import eventlet import socketio import json import requests from app.reader import Reader sio = socketio.Server(cors_allowed_origins='*') app = socketio.WSGIApp(sio) hintCounter = 1 reader = Reader() db_data = {} # return all elements containing key <key> set to value <value> # based on https://stackoverflow.com/questions/9807634/ # find-all-occurrences-of-a-key-in-nested-dictionaries-and-lists def gen_dict_extract(var, key, value): if isinstance(var, list): for d in var: for result in gen_dict_extract(d, key, value): yield result elif isinstance(var, dict): for k, v in var.items(): if k == key and v == value: yield var if isinstance(v, dict) or isinstance(v, list): for result in gen_dict_extract(v, key, value): yield result else: print('UNEXPECTED:', var)
from app.reader import Reader reader = Reader() assignment = reader.assignment_from_json_file('../example_files/block_example.json') api_response = reader.data_from_json('../example_files/block_example.json') reconstructed_response = assignment.to_json(2) print(api_response == reconstructed_response) # assignment -> answer -> lines -> equation -> expression -> # convert answer to question 2 back to json print('Reconstructed data:', assignment.to_json(2)) print() # print the first line's first expression json print("First line's first expression: ", assignment.answers[0].lines[0].expressions[0].to_json()) print() # print first line's json print("First line's expression", assignment.answers[0].lines[0].to_json()) print() # print 0-th index answer's json print(assignment.answers[0].to_json()) print()
def test_to_json(): reader = Reader() assignment = reader.from_json_file('./example_files/block_example.json') api_response = reader.data_from_json('./example_files/block_example.json') reconstructed_response = assignment.to_json(2) assert api_response == reconstructed_response
def test_load_data(): reader = Reader() api_response = reader.data_from_json('./example_files/block_example.json')
def test_read_json_file(): reader = Reader() assignment = reader.from_json_file('./example_files/block_example.json')
def start(self): Engine.readConfiguration() Reader.readFiles(workingYear=Engine.workingYear, BBLIndex=Engine.BBLFieldIndex, APPBBLIndex=Engine.APPBBLFieldIndex)