Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .ipynb_checkpoints/covidScrapen-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"import pandas as pd\n",
"import numpy as np\n",
"from pymaran import gSheets,mail\n",
"import datetime"
"import datetime\n",
"\n"
]
},
{
Expand Down Expand Up @@ -40,7 +41,7 @@
" for tr in tbody:\n",
" temp_data = []\n",
" for td in tr:\n",
" #print(td.text_content())\n",
" print(td.text_content())\n",
" temp_data.append(td.text_content())\n",
" df.loc[count] = temp_data\n",
" count += 1\n",
Expand Down Expand Up @@ -127,7 +128,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.9"
}
},
"nbformat": 4,
Expand Down
977 changes: 977 additions & 0 deletions Untitled.ipynb

Large diffs are not rendered by default.

107 changes: 72 additions & 35 deletions covidScrapen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,122 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'pymaran'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1-ecdce26d27c3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mnumpy\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 5\u001b[0;31m \u001b[0;32mfrom\u001b[0m \u001b[0mpymaran\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mgSheets\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mmail\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 6\u001b[0m \u001b[0;32mimport\u001b[0m \u001b[0mdatetime\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'pymaran'"
]
}
],
"source": [
"import requests\n",
"from lxml import html\n",
"import pandas as pd\n",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hola


Reply via ReviewNB

"import numpy as np\n",
"from pymaran import gSheets,mail\n",
"from pymaran import gSheets, mail\n",
"import datetime"
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def scrap2sheet(url, \n",
" xPath='//*[@id=\"main\"]/div[1]/table/*', \n",
" tableElement=2, \n",
" autoDate=True, \n",
" manualDate='', \n",
" n_cols = 5):\n",
"def scrap2sheet(\n",
" url,\n",
" xPath='//*[@id=\"main\"]/div[1]/table/*',\n",
" tableElement=2,\n",
" autoDate=True,\n",
" manualDate=\"\",\n",
" n_cols=5,\n",
"):\n",
" global tree\n",
" \n",
"\n",
" ### https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Fallzahlen.html\n",
" pageContent=requests.get(url)\n",
" pageContent = requests.get(url)\n",
" tree = html.fromstring(pageContent.content)\n",
" table = tree.xpath(xPath)\n",
" tbody = table[tableElement]\n",
" df_col = range(n_cols)\n",
" #df_col = ['city','total_cases','daily_cases','cases_per_M','total_deaths','']\n",
" # df_col = ['city','total_cases','daily_cases','cases_per_M','total_deaths','']\n",
" df = pd.DataFrame(columns=df_col)\n",
" count = 0\n",
" for tr in tbody:\n",
" temp_data = []\n",
" for td in tr:\n",
" #print(td.text_content())\n",
" print(td.text_content())\n",
" temp_data.append(td.text_content())\n",
" df.loc[count] = temp_data\n",
" count += 1\n",
" if autoDate:\n",
" df.loc[:,'date'] = datetime.date.today()\n",
" df['date'] = df['date'].astype(str)\n",
" df.loc[:, \"date\"] = datetime.date.today()\n",
" df[\"date\"] = df[\"date\"].astype(str)\n",
" else:\n",
" df['date'] = manualDate\n",
" sheet = gSheets.readSheet('covidCrawlen')\n",
" \n",
" \n",
" df[\"date\"] = manualDate\n",
" sheet = gSheets.readSheet(\"covidCrawlen\")\n",
"\n",
" ### Save parsed data\n",
" \n",
"\n",
" df[1] = pd.to_numeric(df[1])\n",
" df[4] = pd.to_numeric(df[4])\n",
" df.loc[df[1].apply(lambda x: ~ (float(x) == np.floor(x))),1] = df[1]*1000\n",
" df.columns = ['city','total_cases','new_cases','deaths_per_M','total_deaths','date']\n",
" df = df.reindex(['city','total_cases','total_deaths','date'],axis=1)\n",
" sheet = gSheets.readSheet('covidCrawlen')\n",
" worksheet = sheet.worksheet('data')\n",
" for i,r in df.iterrows():\n",
" df.loc[df[1].apply(lambda x: ~(float(x) == np.floor(x))), 1] = df[1] * 1000\n",
" df.columns = [\n",
" \"city\",\n",
" \"total_cases\",\n",
" \"new_cases\",\n",
" \"deaths_per_M\",\n",
" \"total_deaths\",\n",
" \"date\",\n",
" ]\n",
" df = df.reindex([\"city\", \"total_cases\", \"total_deaths\", \"date\"], axis=1)\n",
" sheet = gSheets.readSheet(\"covidCrawlen\")\n",
" worksheet = sheet.worksheet(\"data\")\n",
" for i, r in df.iterrows():\n",
" worksheet.append_row(list(r))\n",
" print('success' + str(datetime.date.today()))\n",
" print(\"success\" + str(datetime.date.today()))\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'datetime' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-82306a5f2cfc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m df = scrap2sheet(\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;34m'https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Fallzahlen.html'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'scrap2sheet' is not defined",
"\nDuring handling of the above exception, another exception occurred:\n",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-2-82306a5f2cfc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 8\u001b[0m 5)\n\u001b[1;32m 9\u001b[0m \u001b[0;32mexcept\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 10\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'error'\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdatetime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdate\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtoday\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'datetime' is not defined"
]
}
],
"source": [
"try:\n",
" df = scrap2sheet(\n",
" 'https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Fallzahlen.html',\n",
" \"https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Fallzahlen.html\",\n",
" '//*[@id=\"main\"]/div[1]/table/*',\n",
" 2,\n",
" True, \n",
" '', \n",
" 5)\n",
" True,\n",
" \"\",\n",
" 5,\n",
" )\n",
"except:\n",
" print('error' + str(datetime.date.today()))"
" print(\"error\" + str(datetime.date.today()))"
]
},
{
Expand Down Expand Up @@ -127,7 +164,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.8.9"
}
},
"nbformat": 4,
Expand Down
7 changes: 5 additions & 2 deletions gDown.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
}
],
"source": [
"gdown.download(\"https://drive.google.com/uc?id=1tq8l92xs3AQFGbUayahhDZJmcQfrriiX2HSuQyK85uc\",'lala.csv')"
"gdown.download(\n",
" \"https://drive.google.com/uc?id=1tq8l92xs3AQFGbUayahhDZJmcQfrriiX2HSuQyK85uc\",\n",
" \"lala.csv\",\n",
")"
]
},
{
Expand Down Expand Up @@ -234,7 +237,7 @@
}
],
"source": [
"pd.read_csv('lala.csv')"
"pd.read_csv(\"lala.csv\")"
]
},
{
Expand Down
Loading