import requests as r
import pprint as pprint
from github import Github
import pandas as pd
import numpy as np
# or using an access token
g = Github("XXXXXXXXXXXXXXXX")
#create a loading pipeline
import requests
from pprint import pprint
# github username
username = "risenW"
#check validation
#url to request
url = f"https://api.github.com/users/{username}"
# make the request and return the json
user_data = requests.get(url).json()
user = g.get_user(username)
for repo in user.get_repos():
reposs = repo
lan = repo.language
l = str(lan)
data = {'name': user_data['name'],
'num_repo' : user_data['public_repos']
}
df = pd.DataFrame(data, columns = ['name','num_repo'],index=[0])
print(df)
engine = sqlalchemy.create_engine(DATABASE_LOCATION)
conn = sqlite3.connect('my_played_tracks.sqlite')
cursor = conn.cursor()
sql_query = """CREATE TABLE IF NOT EXISTS my_played_tracks(
name VARCHAR(200),
repo VARCHAR(200),
CONSTRAINT primary_key_constraint PRIMARY KEY (name, repo)
)
"""
cursor.execute(sql_query)
print("Opened database successfully")
try:
df.to_sql("my_played_tracks", engine, index=False, if_exists='append')
except:
print("Data already exists in the database")
conn.close()
print("Close database successfully")
#
#load to a google big query datawarehouse
name num_repo
0 Rising Odegua 59
Opened database successfully
Data already exists in the database
Close database successfully
from pandas.io import gbq
import sqlalchemy
from sqlalchemy.orm import sessionmaker
import sqlite3
DATABASE_LOCATION = "sqlite:///my_played_tracks.sqlite"
df.to_gbq(destination_table = 'sample.sample',
project_id = 'thread-290523',
if_exists = 'replace')
Please visit this URL to authorize this application: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=725825577420-unm2gnkiprugilg743tkbig250f4sfsj.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fbigquery&state=USm5qqqzFY2wutND2vqDKpHxjPxmqh&prompt=consent&access_type=offline
Enter the authorization code: 4/5wE7SssoVOePf9J95NY_Ae0OmnA510J11TrMHfzZ5RmggXdxau-qwA4
1it [00:06, 6.46s/it]