Created
November 30, 2017 06:51
-
-
Save fanian/1276466ea3ab25f9321812c42bb01935 to your computer and use it in GitHub Desktop.
POST from python and nested loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, json | |
open('output.txt', 'w').close() | |
with open('towns.txt') as f: | |
lines = f.readlines() | |
length = len(lines) | |
i = 0 | |
while i < length: | |
for j in range(i, length): | |
begin = lines[i].strip('\n') | |
end = lines[j].strip('\n') | |
headers = {'content-type': 'application/x-www-form-urlencoded'} | |
payload = {'from': begin, 'to': end, 'class': 1} | |
r = requests.post("http://taxi-avrora-krim.ru/php/upload-price.php", data=payload, headers=headers, verify=False) | |
#print(lines[i].rstrip('\n'), end=',') | |
#print(lines[j].rstrip('\n'), end=',') | |
#data = json.loads(r.text) | |
#print(data['price']) | |
with open('output.txt', 'a') as of: | |
data = json.loads(r.text) | |
t_output = lines[i].rstrip('\n') | |
n_output = lines[j].rstrip('\n') | |
p_output = data['price'] | |
print(f"{t_output}, {n_output}, {p_output}", file=of) | |
i += 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment