Skip to content

Commit

Permalink
Merge pull request #3 from jonasschultheiss/emustafa/recom
Browse files Browse the repository at this point in the history
Emustafa/recom
  • Loading branch information
emustafa96 committed Oct 29, 2023
2 parents e7864d0 + 508f1f0 commit 4305573
Show file tree
Hide file tree
Showing 3 changed files with 564 additions and 0 deletions.
133 changes: 133 additions & 0 deletions recommander/data_gen.ipynb
@@ -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
}

0 comments on commit 4305573

Please sign in to comment.