def compare_with_hashtable(file: Path) -> bool: """Takes a file and calculates the sha1 of the file. Afterward it is compared against the sha1 hashes stored in the database under the same filename. :param file: Insert any file as string :return: True (Hash matches the Hash in the db, False (Hashes don't match) or None (Object not in Hash database) """ app = create_app() app.app_context().push() file_basename = file.name hashmap_object = db.session.query(HashModel.object_name, HashModel.object_hash).filter_by( object_name=file_basename).first() # If object not found return None if hashmap_object is None: return False # Else compare file and hashobject hash_from_file = file_hash(file) hash_from_hashdb = hashmap_object.object_hash # Return the equivalent response for the comparison if hash_from_file == hash_from_hashdb: return True else: return False
def __init__(self): self.cfd_data_in_db = CarFuelData().get_cfd_data(ordered=True) self.wiki_matcher = None self.missed_matches = [] self.matched_cars = [] self.matching_score = 1 self.complex_matching = False self.app = create_app()
def setUpClass(cls): if os.environ == 'TESTING': super(BaseTestCase, cls).setUpClass() cls.app = create_app() cls.db = database.db cls.db.app = cls.app cls.db.create_all() else: logger.log("Testing not in os.environ Skipping Database tests.")
def eurostat_update(): app = create_app() app.app_context().push() file_management.create_directory(temp_folder) file_management.clean_directory(temp_folder) history_2005 = download_file(oil_history_2005_url) if history_2005 is not None: # Update 2005 fuel history compare_result = compare_with_hashtable(history_2005) if compare_result: print("Eurostat prices after 2005 up to date") pass else: print("Updating Eurostat prices after 2005") country_codes = countries_driver.CountryData().get() history2005 = ESData(history2005=True).get( country_codes=country_codes) parser.parse_eurostat(history2005)
from openfuelservice.server.db_import.models import * from openfuelservice.server.drivers.carfueldata_driver import LatestCars from openfuelservice.server.drivers.countries_driver import CountryData from openfuelservice.server.drivers.envirocar_driver import ECData from openfuelservice.server.drivers.eurostat_driver import ESData from openfuelservice.server.drivers.misc_driver import EnvirocarWikiMatcher, CarFuelDataWikiMatcher from openfuelservice.server.drivers.wikipedia_driver import get_wikipedia_car_data, ProcessWikipediaCarTexts from openfuelservice.server.statistics.misc_statistics import EnvirocarAverageCategoryStatistics, \ CFDAverageCategoryStatistics from openfuelservice.server.utils.database.database_tools import DBSetup, clear_tables from openfuelservice.server.utils.database.queries import get_relevevant_brands from openfuelservice.server.utils.matching.tf.create_models import ManufacturerANNModelCollection from openfuelservice.server.utils.matching.tf.matching_assessment import AnnMatchingRefinement, FixedMatchingAssessment from openfuelservice.server.utils.misc import file_management app = create_app() cli = FlaskGroup(create_app=create_app) server_mode = ofs_settings['general']['server_mode'] @cli.command() def test(): """Runs the unit tests without test coverage.""" tests = unittest.TestLoader().discover('openfuelservice/tests', pattern='test*.py') result = unittest.TextTestRunner(verbosity=2).run(tests) if result.wasSuccessful(): return 0 return 1
def envirocar_update(): app = create_app() app.app_context().push() envirocar_data = ECData(all_parameters_min=True).get() parser.parse_envirocar(envirocar_data=envirocar_data)