예제 #1
0
def run(export_from, export_to):
    if config.OPTIMIZE_EXPORT_FROM:
        export_from = func.get_last_date(export_from, CHECK_LAST_DATE_FILE)
    logger.info("Getting Acquisition reports")
    bucket_name = config.GCP_PLAY_STORE_REPORTS_BUCKET_NAME
    logger.info(f"Connecting to GCP bucket {bucket_name}")
    play_store_bucket = bucket.BucketGcp(bucket_name)
    logger.info(f"Getting data starting from {export_from}")
    saved_files = download_reports(export_from, play_store_bucket)
    logger.info("Acquisition reports saved")
    logger.info("Updating export data")
    for date, monthly_data in saved_files.items():
        total_data_filename = monthly_data["total"]
        organic_data_filename = monthly_data["organic"]
        logger.info(
            f"Reading data from files: {total_data_filename}, {organic_data_filename}"
        )
        exporter = export.PlayStoreExport(
            total_data_filename, organic_data_filename, "play_store"
        )
        exporter.read_all()
        logger.info("Exporting downloads")
        exporter.export_downloads()
        logger.info("Exporting convertsion rates")
        exporter.export_convertion_rates()
        logger.info("Exporting page_views")
        exporter.export_page_views()
        logger.info("Data updated")
        exporter.upload_files()
        logger.info("Upload data to s3 done")
예제 #2
0
 def test_export_downloads(self, play_store_raw_data):
     exporter = export.PlayStoreExport("play_store.csv",
                                       "play_store_organic.csv",
                                       "export_play_store")
     exporter.read_all()
     exporter.export_downloads()
     assert os.path.exists(exporter.files_saved[0]) is True
예제 #3
0
 def test_saving_export_updates_old_file(self, play_store_raw_data):
     exporter = export.PlayStoreExport("play_store.csv",
                                       "play_store_organic.csv",
                                       "export_play_store")
     exporter.export_daily({"2019-06-01": {"es": 1, "pr": 2}}, "downloads")
     exporter.export_daily({"2019-06-02": {"es": 4, "pr": 4}}, "downloads")
     with open(exporter.files_saved[0]) as file:
         assert len(file.readlines()) == 3
예제 #4
0
 def test_saving_export_creates_new_files(self, play_store_raw_data):
     EXPECTED_KPI = 2
     EXPECTED_AGGREGATIONS = 3
     exporter = export.PlayStoreExport("play_store.csv",
                                       "play_store_organic.csv",
                                       "export_play_store")
     exporter.read_all()
     exporter.export_downloads()
     exporter.export_convertion_rates()
     assert (len(os.listdir(exporter.exported_data_dir)) == EXPECTED_KPI *
             EXPECTED_AGGREGATIONS)
예제 #5
0
 def test_exported_data_dictrionary(self, play_store_raw_data):
     exporter = export.PlayStoreExport("play_store.csv",
                                       "play_store_organic.csv",
                                       "export_play_store")
     exporter.read_all()
     assert exporter.downloads["2019-03-01"]["br_organic"] is not None
예제 #6
0
 def test_reading_from_not_existing_file_raise(self):
     with pytest.raises(export.NoRawDataForPlayStore):
         exporter = export.PlayStoreExport("play_store.csv",
                                           "play_store_organic.csv",
                                           "export_play_store")
         exporter.read_raw_data()
예제 #7
0
 def test_reading_raw_data_creates_dictionary(self, play_store_raw_data):
     exporter = export.PlayStoreExport("play_store.csv",
                                       "play_store_organic.csv",
                                       "export_play_store")
     exporter.read_raw_data()
     assert exporter.raw_data[0]["date"] == "2019-03-01"
예제 #8
0
def play_store_exporter():
    return play_store_export.PlayStoreExport(
        "play_store.csv", "play_store_organic.csv", "play_store"
    )