102 lines
2.6 KiB
Plaintext
102 lines
2.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from datetime import datetime\n",
|
|
"import pytz"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Imports: \n",
|
|
"* datetime: parse epoch time from listings, compare to current time\n",
|
|
"* pytz: specify timezone for datetime operations"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class listing:\n",
|
|
" ID = None\n",
|
|
" title = None\n",
|
|
" desc = None\n",
|
|
" time = None\n",
|
|
" price = None\n",
|
|
" condition = None\n",
|
|
" location = None # requires visiting listing URL\n",
|
|
" image = None\n",
|
|
" url = None\n",
|
|
" seller = None\n",
|
|
" likes = None\n",
|
|
" diffTime = None\n",
|
|
" listtype = None # bump, new user etc\n",
|
|
"\n",
|
|
" def __init__(self, parsedDict):\n",
|
|
" self.ID = parsedDict['id']\n",
|
|
" self.seller = parsedDict['seller']['username']\n",
|
|
" self.image = parsedDict['photoUrls'][0].replace('_thumbnail','')\n",
|
|
" epochTime = self.image.split('_')[-2]\n",
|
|
" sgTZ = pytz.timezone('Asia/Singapore')\n",
|
|
" currentTime = datetime.now().astimezone(sgTZ)\n",
|
|
" self.time = datetime.fromtimestamp(int(epochTime), tz=sgTZ)\n",
|
|
" self.diffTime = currentTime - self.time\n",
|
|
" self.title = parsedDict['title']\n",
|
|
" self.price = parsedDict['price']\n",
|
|
" self.desc = parsedDict['belowFold'][2]['stringContent']\n",
|
|
" self.condition = parsedDict['belowFold'][3]['stringContent']\n",
|
|
" self.listtype = parsedDict['aboveFold'][0]['component']\n",
|
|
" # self.likes = parsedDict['likesCount'] invalid if no likes yet\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.10.9"
|
|
},
|
|
"metadata": {
|
|
"interpreter": {
|
|
"hash": "22f70f503a14852dda6f3675b02ae61e38835edc56b87f63457d6e30f459ac44"
|
|
}
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|