-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
101 lines (87 loc) · 2.94 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import time
import random
import string
import json
import sys
import platform
import requests
URL = "https://api.wakatime.com/api/v1/users/current/heartbeats"
def random_string(length):
return "".join(
[random.choice(string.ascii_letters + string.digits) for _ in range(length)]
)
def generate_payload(namefile, eksfile, projectname, language):
entity = (
f"{random_string(8)}.{eksfile}"
if namefile == "random"
else f"{namefile}.{eksfile}"
)
project = random_string(12) if projectname == "random" else projectname
return {
"type": "file",
"entity": entity,
"time": time.time(),
"lineno": str(random.randint(1, 9999)),
"cursorpos": str(random.randint(0, 99999)),
"lines": str(random.randint(1, 9999)),
"line_additions": str(random.randint(1, 9999)),
"line_deletions": str(random.randint(1, 9999)),
"is_write": bool(random.getrandbits(1)),
"plugin": random.choice(
["vscode", "pycharm", "sublime", "nano", "micro", "jetbrains"]
),
"project": project,
"language": language,
"project_root_count": random.randint(1, 99),
"category": random.choice(
[
"coding",
"building",
"indexing",
"debugging",
"browsing",
"running tests",
"writing tests",
"manual testing",
"writing docs",
"communicating",
"code reviewing",
"researching",
"learning",
"designing",
]
),
"branch": random.choice(["main", "master", "dev"]),
}
def main(apikey, namefile, eksfile, projectname, language):
querystring = {"api_key": apikey}
headers = {"Content-Type": "application/json", "X-Machine-Name": platform.node()}
try:
while True:
try:
payload = generate_payload(namefile, eksfile, projectname, language)
response = requests.post(
URL, json=payload, headers=headers, params=querystring, timeout=1500
)
print(json.dumps(response.json(), indent=2))
time.sleep(random.randint(1, 4))
except requests.exceptions.RequestException as err:
print(f"An error occurred when sending request: {err}")
except KeyboardInterrupt:
print("\nProgram interrupted by user. Exiting...")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) != 6:
print(
"Usage: python script.py <apikey> <namefile> <extensionfile> <projectname> <language>"
)
sys.exit(1)
a = sys.argv[1]
if len(a) < 1 or not "waka_" in a:
print("Invalid API Key!")
sys.exit(1)
b = sys.argv[2]
c = sys.argv[3]
d = sys.argv[4]
e = sys.argv[5]
main(a, b, c, d, e)