Exemplo n.º 1
0
import requests
import json
import re
import sys
import os
import db_functions as db
from APIRequest import get_request_pcr, print_components, set_http_pcr

conn = db.get_connection()
print("Currently in db:")
db.doQuery(conn, "select count(*) from Professor;")
http_str = set_http_pcr("instructors")
json_obj = get_request_pcr(http_str)
instr_list = json_obj["result"]["values"]
for item in instr_list:
    # need to use tripple quotes because some names have ' in them
    # instructors have -1 as default avg rating
    pid = "{0}".format(item["id"])
    just_the_num = pid.split("-")[0]
    query_str = """insert into Professor (pid,name,avg_rating) VALUES("{0}","{1}",-1);""".format(
        just_the_num, item["name"])
    db.doQuery(conn, query_str)
db.close(conn)
            print('{0} cells updated.'.format(result.get('updatedCells')))
            #exit()
        else:
            print("row changed during update")
    else:
        print("animalid not found", animalid)
    count += 1
    prev_animalid = animalid

now = datetime.datetime.now()
print(now)
range_name = tab + 'A1'
print(range_name)
values = [
    ["Last full update " + str(now)],
    # Additional rows ...
]
body = {'values': values}
result = service.spreadsheets().values().update(
    spreadsheetId=config.spreadsheet_id,
    range=range_name,
    valueInputOption=value_input_option,
    body=body).execute()
print('{0} cells updated.'.format(result.get('updatedCells')))

#Close the DB connection
db_functions.close(cnxn, cursor)
now = datetime.datetime.now()
current_timestamp = (now.strftime('%Y-%m-%d %H:%M:%S'))
print("success: " + current_timestamp)