Skip to content

Instantly share code, notes, and snippets.

@FelixChop
Created September 12, 2019 05:54
Show Gist options
  • Select an option

  • Save FelixChop/7cd16a4939cfea10dda56c3c658e2c96 to your computer and use it in GitHub Desktop.

Select an option

Save FelixChop/7cd16a4939cfea10dda56c3c658e2c96 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b5764db7ddc444fe979b101d88c839de",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=1, bar_style='info', max=1), HTML(value='')))"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"0/|/| 0/? [00:00<?, ?it/s]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import os\n",
"import ast\n",
"import time\n",
"import string\n",
"from tqdm import tqdm_notebook\n",
"tqdm_notebook()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def files():\n",
" return [t for t in os.listdir(os.curdir) if t.endswith('.txt')]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def open_dic(path):\n",
" with open(path, 'r') as f:\n",
" return ast.literal_eval(f.read())"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def get_all_artists():\n",
" final_dic = {}\n",
" total_scraped = 0\n",
" for path in files():\n",
" new_dic = open_dic(path)\n",
" total_scraped += len(new_dic)\n",
" final_dic = {**final_dic, **new_dic}\n",
" return final_dic, len(final_dic), total_scraped"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def update_status_all_bots(pbars):\n",
" f = files()\n",
" for l in string.ascii_lowercase:\n",
" pbars[l].update(-pbars[l].last_print_n)\n",
" pbars[l].update(len([x for x in f if x.replace('artists_','').startswith(l)]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "285db03f1f034a31a6e891335b48aa85",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='a', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a24c4317200d4cb3b14969fad5ce0c49",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='b', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4be9454f6aec4e5bbef46e16bea9fc16",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='c', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0c4ce916bf9b4bb19e0a71eebd0e64e5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='d', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5cbbf300644842278c65e8f1b6d1bbf7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='e', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "620cbd2ef5644b50819544916a8c0894",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='f', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "2eb7f49471ac413db2fda8c35486f2e3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='g', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "812378f9692443a892439be1f9bf194e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='h', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09a84896d85a4d3385b710a0f11a8eb8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='i', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5c95fc095dcb4933b9d74e295d309f16",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='j', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8b72dcb4f77443a8b8d2073d3fff4e4b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='k', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "ec85aedcba5e4981944e2c7f399c2d4d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='l', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3e8dccedf6804704b7d71a31a788987e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='m', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "aa6bbec2536f492b9a2e3d313f99ab20",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='n', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "1be2b5713de54e39b7c5e871556afe9f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='o', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b303be250a5e48f48ec339b7a33372c8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='p', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "31e41a7052094d71882138ca1508daa5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='q', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f8dfae6035b14f7ab068059302b879bc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='r', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bfbb4b6dfc41447c83ae143ca4653306",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='s', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "c97e93ec3bd74881b3bf1d18abf0db09",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='t', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dcb6a848f38845cea8a2cd68e871224e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='u', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "594a1e713f154b01a48ec2cf1dbe1f1e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='v', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6944be3b80c04ffc8c972d07d39496f8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='w', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b30d514327654e0395d59508f7009e52",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='x', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "10019ac75eab4d1c8d71438bf95ab70f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='y', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "60a52faec6614b1e8220bdf7bef56a79",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(IntProgress(value=0, description='z', max=26, style=ProgressStyle(description_width='initial'))…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of unique artists: 38174 --- Duplicates: 1153\r"
]
}
],
"source": [
"pbars = {l:tqdm_notebook(total=26, desc=l) for l in string.ascii_lowercase}\n",
"\n",
"while True:\n",
" final_dic, total_artists, total_scraped = get_all_artists()\n",
" print('Number of unique artists:', total_artists, ' --- Duplicates:', total_scraped - total_artists, end='\\r')\n",
" update_status_all_bots(pbars)\n",
" time.sleep(5)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment