Skip to content

Instantly share code, notes, and snippets.

@fanian
Created November 30, 2017 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanian/1276466ea3ab25f9321812c42bb01935 to your computer and use it in GitHub Desktop.
Save fanian/1276466ea3ab25f9321812c42bb01935 to your computer and use it in GitHub Desktop.
POST from python and nested loop
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