def main(): """ main-method build file paths ask for database access and build basic structure """ parser = argparse.ArgumentParser(description='Build DB') parser.add_argument('--logging', dest='log', action='store_true', help='activate logging') args = parser.parse_args() home = Path(__file__).absolute().parent.parent if not os.path.exists(Path.joinpath(home, 'logging')): os.makedirs(Path.joinpath(home, 'logging')) zip_file = Path.joinpath(home, 'data', 'zipcodes.de.csv') bev_file = Path.joinpath(home, 'data', 'bev.csv') bevg_file = Path.joinpath(home, 'data', 'bev_gruppe.csv') log_file = Path.joinpath(home, 'logging', 'build_corona_db.log') if args.log: logging.basicConfig(filename=log_file, level=logging.INFO) cred = credentials() create_corona_db(cred, args.log) with psycopg2.connect(dbname=cred.dbname, user=cred.username, password=cred.password, host=cred.host, port=cred.port) as conn: create_tables(conn, args.log) init_db(conn, str(zip_file), str(bev_file), str(bevg_file), args.log) return
def get_build(provider, repo, build_num): url = URL_TEMPLATE.format(provider, repo, build_num) password = credentials.credentials() response = requests.get(url, params={"circle-token": password}) if response.status_code == 404: print("Got 404 from Circle", file=sys.stderr) sys.exit(1) elif response.status_code != 200: print(response.json(), file=sys.stderr) sys.exit(1) return response.json()
def main(): """ main-method parses target file path, establishes connection, creates + executes query and writes results to target """ parser = argparse.ArgumentParser(description='file to write to') parser.add_argument('file', metavar='target-file', nargs=1, help='file that the query-results are written to') parser.add_argument('--guest', dest='guest', action='store_true', help='use guest server-login') parser.add_argument('--logging', dest='log', action='store_true', help='activate logging') args = parser.parse_args() home = Path(__file__).absolute().parent.parent log_file = Path.joinpath(home, 'logging', 'query.log') if args.log: logging.basicConfig(filename=log_file, level=logging.INFO) if args.guest: cred = credentials( 'corona_db', 'guest', 'pw', '193.196.54.54', '5432') else: cred = credentials() with psycopg2.connect( dbname = cred.dbname, user = cred.username, password = cred.password, host = cred.host, port = cred.port) as conn: reader = db_reader(create_query(), conn, args.log) data = reader.read() csv_table(header = data['header'], content = data['content']).write(args.file[0]) return
def get_builds(provider, repo, count, branch, all_builds, only_running=False): if all_builds: branch_argument = "" else: branch_argument = "tree/{}".format(branch) url = URL_TEMPLATE.format(provider, repo, branch_argument) password = credentials.credentials() params = {"circle-token": password, "limit": count} if only_running: params["filter"] = "running" response = requests.get(url, params=params) if response.status_code != 200: print(response.json(), file=sys.stderr) sys.exit(1) return response.json()
def main(): """ downloads newest Version of the RKI_COVID19.csv from opendata.arcgis update cases in DB """ # Parse argument --keep-covid: Do not download new version if found parser = argparse.ArgumentParser(description='Update cases') parser.add_argument('--keep-covid', dest='keep', action='store_true', help='do not replace existing RKI_COVID19.csv') parser.add_argument('--logging', dest='log', action='store_true', help='activate logging') args = parser.parse_args() home = Path(__file__).absolute().parent.parent file = Path.joinpath(home, 'data', 'RKI_COVID19.csv') log_file = Path.joinpath(home, 'logging', 'update.log') if args.log: logging.basicConfig(filename=log_file, level=logging.INFO) # remove existing RKI_COVID19.csv and download newest version if os.path.exists(str(file)) and not args.keep: os.remove(str(file)) if not os.path.exists(str(file)): url = 'https://opendata.arcgis.com/datasets/dd4580c810204019a7b8eb3e0b329dd6_0.csv' wget.download(url, out=str(file)) print('\ndownloaded rki_covid19.csv') data = csv_table(str(file)) data.header[0] = 'ObjectId' # ask for access information, establish connection to DB and update cred = credentials() with psycopg2.connect(dbname=cred.dbname, user=cred.username, password=cred.password, host=cred.host, port=cred.port) as conn: update_covid19(data, conn, args.log) return