-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (49 loc) · 1.6 KB
/
main.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
#!/usr/bin/env python
# coding: utf-8
import steamapi
import time
import os
from dotenv import load_dotenv
load_dotenv(".env")
steam_api_key = os.getenv('STEAM_DEV_API_KEY')
sleep_between_calls = float(os.getenv('SLEEP_BETWEEN_STEAM_CALLS', 2))
if steam_api_key is None:
raise(".env file not set up correctly")
steamapi.core.APIConnection(api_key=steam_api_key, validate_key=True)
inputs = []
with open('steam_ids.txt') as my_file:
for line in my_file:
if len(line) > 10:
inputs.append(line.replace("\n", ""))
def norm_end(string):
if string[-1] == "/":
string = string[:-1]
return string
def extract_id_from_profile_url(url):
return url.split("/")[-1]
def extract_id_from_id_url(url):
steam_profile_name = url.split("/")[-1]
steamid = str(steamapi.user.SteamUser(userurl=steam_profile_name).steamid)
time.sleep(2)
return steamid
def is_profile_url(url):
return (
"://steamcommunity.com/profiles/" in
url[0:len('https://steamcommunity.com/profiles/')]
)
def get_id64(inputs_norm_end):
output = []
for input_url in inputs_norm_end:
print("running for",input_url)
if is_profile_url(input_url):
output.append(extract_id_from_profile_url(input_url))
else:
output.append(extract_id_from_id_url(input_url))
return output
inputs_norm_end = [norm_end(string) for string in inputs]
id_64s = get_id64(inputs_norm_end)
f = open("steam_ids_output.csv", "w")
f.write("URL, steamid64 \n")
for i in range(len(inputs_norm_end)):
f.write(inputs_norm_end[i]+","+id_64s[i]+'\n')
f.close()