-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsend_votes_first_candidates.py
45 lines (40 loc) · 1.4 KB
/
send_votes_first_candidates.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
from random import randint
import requests
from requests.structures import CaseInsensitiveDict
response = requests.get("http://localhost:8080/api/vma/registry/current")
urlArtist = "http://localhost:8080/api/vma/voting/artist"
urlSong = "http://localhost:8080/api/vma/voting/song"
open_voting = "http://localhost:8080/api/vma/voting/open"
open_result = requests.get(open_voting).json()
print(open_result)
headers = CaseInsensitiveDict()
user_id = open_result['id']
headers["Cookie"] = f"votingId={user_id}"
for category in response.json():
print(category["category"])
print(category)
if category["type"] == "ARTIST":
elected = category["artists"][randint(0, len(category['artists'])-1)]
resp = requests.post(
urlArtist,
headers=headers,
json={
"userId": user_id,
"idC": category["id"],
"idA": elected["id"]
})
print(resp.status_code)
if category["type"] == "SONG" or category["type"] == "INSTRUMENTAL":
elected = category["songs"][randint(0, len(category['songs'])-1)]
payload = {
"userId": user_id,
"idC": category["id"],
"idS": elected["id"]
}
resp = requests.post(
urlSong,
headers=headers,
json=payload)
print("=======")
print(payload)
print(resp.status_code)