コード例 #1
0
                    type=int,
                    default=None,
                    help='Telegram chat id')
parser.add_argument('--username',
                    type=str,
                    default=None,
                    help='Telegram username')
parser.add_argument('--email',
                    type=str,
                    default=None,
                    help='Gravatar email address')

if __name__ == '__main__':
    args = parser.parse_args()
    if args.command == 'setup_db':
        db_setup(settings)
    elif args.command == 'populate_data':
        populate_dummy_history(settings,
                               date_range=args.range,
                               username=args.username)
    elif args.command == 'add_user':
        if not args.chat_id:
            print("Please, provide chat_id for the user!")
            sys.exit(1)
        if not args.username:
            print("Please, provide username for the user!")
            sys.exit(1)
        if not args.email:
            print("Please, provide email for the user!")
            sys.exit(1)
        if not save_user(settings,
コード例 #2
0
    if not record or not record[0] or not record[0][0] or not record[0][
            1] or not record[0][2]:
        crash_data[crash]['int_id'] = None
        crash_data[crash]['longitude'] = None
        crash_data[crash]['latitude'] = None
        return

    crash_data[crash]['int_id'] = record[0][0]
    crash_data[crash]['latitude'] = record[0][1]
    crash_data[crash]['longitude'] = record[0][2]


if __name__ == '__main__':
    print("crash_location.py: Producing crash locations point outputs")
    cursor, conn = db_setup()
    crash_data = read_crash_csv()

    total_crashes = len(crash_data)
    i = 0
    progress_bar_setup()
    for crash in crash_data:
        i += 1
        progress_bar_increment(i, total_crashes)
        add_gps(crash_data, crash, cursor)
    progress_bar_finish()

    location_found = 0
    location_not_found = 0
    for crash in crash_data:
        if crash_data[crash]['longitude']:
コード例 #3
0
    db_name = input("Postgres database name:").strip()
    raw_crash = input("CSV with raw crash data:").strip()

    personal_data = {
        "postgres_username": username,
        "postgres_password": password,
        "postgres_database_name": db_name,
        "raw_crash_csv": raw_crash
    }

    with open(PERSONAL_FILE,'w') as fp:
        fp.write(json.dumps(personal_data, default=str, indent=4))

    # test database connection
    from utils import db_setup, clean_date
    if not db_setup():
        sys.exit(1)

    # test raw_crash_path
    try:
        with open("data/{}".format(raw_crash)) as csv_file:
            csv_reader = csv.reader(csv_file, delimiter=',')
            try:
                for index, row in enumerate(csv_reader):
                    if len(row) != CSV_FIELDS:
                        print("Error: Provided CSV not properly formatted",file=sys.stdout)
                        sys.exit(1)
                    try:
                        if index != 0:
                            clean_date(row[CSV_DATE_FIELD])
                    except: