Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cfc8de

Browse filesBrowse files
committed
Google API
1 parent 3e9b41a commit 7cfc8de
Copy full SHA for 7cfc8de

7 files changed

+155-1Lines changed: 155 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file
  • Display the source diff
  • Display the rich diff
File renamed without changes.
Collapse file
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
import googlemaps
77

8-
gmaps = googlemaps.Client(key='AIzaSyBiC8vKEEF-MLP9a2de0PLs-S_XrEL0kSQ')
8+
API_KEY = '<YOUR-API-KEY>'
9+
10+
gmaps = googlemaps.Client(key=API_KEY)
911

1012
results = gmaps.places('Rugby Club, London')
1113

Collapse file
+16Lines changed: 16 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
# List YouTube comments using Google API
3+
4+
Three versions:
5+
6+
- using standard modules urllib and json (main-urllib.py),
7+
- using popular module requests (main-requests.py),
8+
- using official Google's module (main-module.py).
9+
10+
[Google API for "commentThreads"](https://developers.google.com/youtube/v3/docs/commentThreads/list)
11+
12+
[Example video on YouTube to get comments](https://www.youtube.com/watch?v=oVp1vrfL_w4&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M)
13+
14+
[Python module for Google API (not used in example)](https://github.com/google/google-api-python-client)
15+
16+
[Google Console for Developers (to register application and get API_KEY)](https://console.developers.google.com/)
Collapse file
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
# Google API for "commentThreads":
4+
# https://developers.google.com/youtube/v3/docs/commentThreads/list
5+
#
6+
# Example video on YouTube video to get comments:
7+
# https://www.youtube.com/watch?v=oVp1vrfL_w4&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
8+
#
9+
# Python module for Google API (not used in example)
10+
# https://github.com/google/google-api-python-client
11+
#
12+
# Google Console for Developers (to register application and get API_KEY)
13+
# https://console.developers.google.com/
14+
15+
import googleapiclient.discovery
16+
17+
API_KEY = '<YOUR-API-KEY>'
18+
19+
service = googleapiclient.discovery.build('youtube', 'v3', developerKey=API_KEY)
20+
21+
data = {
22+
'part': 'snippet',
23+
'videoId': 'oVp1vrfL_w4',
24+
#'order': 'time',
25+
}
26+
27+
request = service.commentThreads().list(**data)
28+
#request = service.commentThreads().list(part='snippet', videoId='oVp1vrfL_w4')
29+
30+
result = request.execute()
31+
32+
for item in result['items']:
33+
print(item['snippet']['topLevelComment']['snippet']['authorDisplayName'])
34+
print('---')
35+
print(item['snippet']['topLevelComment']['snippet']['textDisplay'])
36+
#print(item['snippet']['topLevelComment']['snippet']['textOriginal'])
37+
print('====================')
Collapse file
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python3
2+
3+
# Google API for "commentThreads":
4+
# https://developers.google.com/youtube/v3/docs/commentThreads/list
5+
#
6+
# Example video on YouTube video to get comments:
7+
# https://www.youtube.com/watch?v=oVp1vrfL_w4&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
8+
#
9+
# Python module for Google API (not used in example)
10+
# https://github.com/google/google-api-python-client
11+
#
12+
# Google Console for Developers (to register application and get API_KEY)
13+
# https://console.developers.google.com/
14+
15+
import requests
16+
17+
API_KEY = '<YOUR-API-KEY>'
18+
19+
data = {
20+
'key': API_KEY,
21+
'part': 'snippet',
22+
'videoId': 'oVp1vrfL_w4',
23+
#'order': 'time',
24+
}
25+
26+
url = 'https://www.googleapis.com/youtube/v3/commentThreads'
27+
28+
response = requests.get(url, params=data)
29+
30+
result = response.json()
31+
32+
for item in result['items']:
33+
print(item['snippet']['topLevelComment']['snippet']['authorDisplayName'])
34+
print('---')
35+
print(item['snippet']['topLevelComment']['snippet']['textDisplay'])
36+
#print(item['snippet']['topLevelComment']['snippet']['textOriginal'])
37+
print('====================')
Collapse file
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
3+
# Google API for "commentThreads":
4+
# https://developers.google.com/youtube/v3/docs/commentThreads/list
5+
#
6+
# Example video on YouTube video to get comments:
7+
# https://www.youtube.com/watch?v=oVp1vrfL_w4&list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M
8+
#
9+
# Python module for Google API (not used in example)
10+
# https://github.com/google/google-api-python-client
11+
#
12+
# Google Console for Developers (to register application and get API_KEY)
13+
# https://console.developers.google.com/
14+
15+
import urllib.request
16+
import urllib.parse
17+
import json
18+
19+
API_KEY = '<YOUR-API-KEY>'
20+
21+
data = {
22+
'key': API_KEY,
23+
'part': 'snippet',
24+
'videoId': 'oVp1vrfL_w4',
25+
#'order': 'time',
26+
}
27+
28+
url = 'https://www.googleapis.com/youtube/v3/commentThreads'
29+
30+
params = urllib.parse.urlencode(data)
31+
32+
response = urllib.request.urlopen(url + '?' + params)
33+
34+
result = json.loads(response.read())
35+
36+
for item in result['items']:
37+
print(item['snippet']['topLevelComment']['snippet']['authorDisplayName'])
38+
print('---')
39+
print(item['snippet']['topLevelComment']['snippet']['textDisplay'])
40+
#print(item['snippet']['topLevelComment']['snippet']['textOriginal'])
41+
print('====================')
Collapse file

‎pandas/read_sql/main.py‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python3
2+
3+
import pandas as pd
4+
import pymysql
5+
6+
HOST = input('host [localhost]: ') or 'localhost'
7+
LOGIN = input('login []: ')
8+
PASSWORD = input('password []: ')
9+
DATABASE = input('database [my_database]: ') or 'my_database'
10+
TABLE = input('table [my_table]: ') or 'my_table'
11+
12+
conn = pymysql.connect(HOST, LOGIN, PASSWORD, DATABASE)
13+
14+
query = 'SELECT * FROM {};'.format(TABLE)
15+
df = pd.read_sql(query, conn)
16+
17+
print('len:', len(df))
18+
19+
print( df.head() )
20+
21+

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.