-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBigQuery.py
53 lines (41 loc) · 1.5 KB
/
BigQuery.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
from google.cloud import bigquery
def main():
client = bigquery.Client.from_service_account_json('glassy-life-203401-306be48182fc.json')
repoid_list=[58172287 ,
45936895 ,
36040894 ,
48109239 ,
93444615 ,
147595186 ,
107153495 ,
121444325 ,
145207303 ,
]
for repo_id in repoid_list:
query = create_query(repo_id)
config = bigquery.QueryJobConfig()
config.use_legacy_sql = True
string=''
rows = client.query(query, job_config=config).result()
print(str(repo_id)+" downloading ...")
for row in rows:
#print(row[0])
string = string +'\n'+str(row[0])
file = open(str(repo_id)+'_time.csv', 'w')
file.write(string)
file.close()
def create_query(repo_id):
query = '''
SELECT (STRFTIME_UTC_USEC(TIMESTAMP_TO_USEC(created_at) , "%Y/%m/%d %H:%M:%S")) AS time,
FROM TABLE_DATE_RANGE(
[githubarchive.day.],
TIMESTAMP('2018-09-01'),
TIMESTAMP('2018-09-30')
)
where repo.id = '''+str(repo_id)+'''
and type ='PullRequestEvent'
'''
return query
if __name__ == "__main__":
main()