Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jonasschultheiss/emustafa/recom
Emustafa/recom
- Loading branch information
Showing
3 changed files
with
564 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Art\n", | ||
"Sports\n", | ||
"Politics\n", | ||
"Books\n", | ||
"Movies\n", | ||
"Technology\n", | ||
"Fashion\n", | ||
"Outdoor Activities\n", | ||
"Pets\n", | ||
"Familiy" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import random\n", | ||
"import requests\n", | ||
"import json\n", | ||
"import credentials" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def generate_random_entries(N):\n", | ||
" entries = []\n", | ||
" for _ in range(N):\n", | ||
" entry = {category: random.randint(1, 5) for category in categories}\n", | ||
" entries.append(entry)\n", | ||
" return entries" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mockaroo_url = '\thttps://api.mockaroo.com/api/generate.csv'\n", | ||
"# API key\n", | ||
"num_rows_to_generate = 300 # Max 1000 for the free version of the API" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def post_request():\n", | ||
"\n", | ||
" url = url = mockaroo_url + '?key=' + credentials.mockaroo_key + '&count=' + str(num_rows_to_generate)\n", | ||
"\n", | ||
"\n", | ||
" with open('schema.json', 'r') as datafile:\n", | ||
" fields = json.load(datafile)\n", | ||
" # Make a post call to the URL\n", | ||
" # Body of the post request is the schema definition of the output expected\n", | ||
" response = requests.post(url=url, json=fields)\n", | ||
"\n", | ||
" # Write the output to a file (output.json)\n", | ||
" with open('output.csv', 'w') as outfile:\n", | ||
" outfile.write(response.text)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"post_request()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 31, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"{'Art': 1, 'Sports': 5, 'Politics': 5, 'Books': 3, 'Movies': 2, 'Technology': 1, 'Fashion': 3, 'Outdoor Activities': 5, 'Pets': 4, 'Family': 1}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print(random_entries[0])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "bhack", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.