-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_csv.py
executable file
·83 lines (51 loc) · 1.75 KB
/
create_csv.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Se tivermos o dotenv instalado importamos e setamos
try:
from dotenv import load_dotenv
load_dotenv()
except:
pass
import pandas as pd
import requests
import os
client_id = os.getenv("client_id")
client_secret = os.getenv("client_secret")
def getOAuth():
# Get Oauth Token
url = "https://id.twitch.tv/oauth2/token"
param = {
"client_id": client_id,
"client_secret": client_secret,
"grant_type": "client_credentials"
}
r = requests.post(url, data=param)
access_token = r.json()["access_token"]
header = {"Client-ID": client_id, "Authorization":"Bearer "+ access_token}
return access_token, header
def getStreamerId(streamer, header):
# Get streamer's id
url = "https://api.twitch.tv/helix/users"
param = {"login": streamer}
r = requests.get(url, params=param, headers=header).json()
return r["data"][0]
def createCSV():
""" Com o CSV do bot do twitter cria um novo com as infos para o site """
access_token, header = getOAuth()
df = pd.read_csv("streamers.csv")
df_new = pd.DataFrame([], columns=["Id", "Nome", "Twitch", "Descr", "Avatar"])
print("ENTER")
for streamer in df.loc[:, "Nome"].values:
streamer_data = getStreamerId(streamer, header)
if streamer_data["description"] == "":
streamer_data["description"] = "Descrição Indisponível"
df_new = df_new.append({
"Id": streamer_data["id"],
"Nome": streamer_data["display_name"],
"Twitch": "https://www.twitch.tv/"+streamer_data["login"],
"Descr": streamer_data["description"],
"Avatar": streamer_data["profile_image_url"]
}, ignore_index=True)
df_new.to_csv("streamers_new.csv", index=False)
print("DONE")
if __name__ == "__main__":
# Criar o novo CSV
createCSV()