-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse.py
More file actions
33 lines (26 loc) · 1.08 KB
/
reverse.py
File metadata and controls
33 lines (26 loc) · 1.08 KB
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
import requests
import json
def main():
"""
This file will be used to complete the first challenge for the Code2040 API Challenge
This challenge is asking me to reverse a string
"""
try:
# Initialize info to send post requests
url = 'http://challenge.code2040.org/api/reverse'
post_url = 'http://challenge.code2040.org/api/reverse/validate'
my_token = json.dumps({'token': '3de4e34b13ebc2912ab209a77aec363e'})
headers = {'content-type': 'application/json'}
# Get the string that we will reverse
word = requests.post(url, data=my_token, headers=headers).content
# Reverse the string that we got from the API
reverse = word[::-1]
# Post the reversed string back to the API
answer = json.dumps({'token': '3de4e34b13ebc2912ab209a77aec363e', 'string': reverse})
response = requests.post(post_url, data=answer, headers=headers)
print response.content
except Exception:
# TODO: add logic to handle possible exception types
raise
if __name__ == '__main__':
main()