Last active
November 15, 2017 15:42
-
-
Save cjavad/9699efee7e59e609e8169e48e1fe5c31 to your computer and use it in GitHub Desktop.
A quick script that fetches random data from https://myjson.com (great place by the way)
This file contains hidden or 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
| #!bin/python3 | |
| import sys | |
| import random | |
| from string import digits, ascii_uppercase, ascii_lowercase | |
| from requests import get | |
| base_url = "https://api.myjson.com/bins/" | |
| def gen(): | |
| return ''.join([random.choice(digits + ascii_lowercase) for x in range(5)]) | |
| def a(amount, write = False): | |
| out = list() | |
| i = 0 | |
| while i <= amount: | |
| key = gen() | |
| text = get(base_url + key).text | |
| if str(text) == '{"status":404,"message":"Not Found"}': | |
| pass | |
| else: | |
| if write == "write": | |
| open(key + ".json", "w").write(text) | |
| out.append(key + ".json") | |
| else: | |
| out.append(text) | |
| i += 1 | |
| return out | |
| if len(sys.argv) < 1: | |
| print("Not enough args") | |
| exit() | |
| else: | |
| print(a(int(sys.argv[1]), sys.argv[2])) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Supports writing to files