Created
July 18, 2021 10:39
-
-
Save bruvv/209c1383ae24a7307be38fb28cd8a9c0 to your computer and use it in GitHub Desktop.
download csv convert to HTML
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
import os | |
import requests | |
from datetime import datetime | |
# set environment variables | |
os.environ['USERNAME'] = 'python-demo' | |
os.environ['PASSWORD'] = 'claw30_bumps' | |
city = 'http://rachel.maykinmedia.nl/djangocase/city.csv' | |
hotel = 'http://rachel.maykinmedia.nl/djangocase/hotel.csv' | |
def main(city, hotel): | |
"""download csv file from url with http authentication""" | |
r = requests.get(city, auth=('python-demo', 'claw30_bumps')) | |
if r.status_code == 200: | |
with open('city.csv', 'wb') as f: | |
f.write(r.content) | |
else: | |
print('City file not found') | |
r = requests.get(hotel, auth=('python-demo', 'claw30_bumps')) | |
if r.status_code == 200: | |
with open('hotel.csv', 'wb') as f: | |
f.write(r.content) | |
else: | |
print('Hotel file not found') | |
convert_csv_to_html() | |
def convert_csv_to_html(): | |
"""convert csv files to html files""" | |
import pandas as pd | |
import webbrowser | |
a = pd.read_csv("city.csv") | |
b = pd.read_csv("hotel.csv") | |
# assign it to variable (string) | |
html_filea = a.to_html() | |
html_fileb = b.to_html() | |
f = open('index.html','w') | |
message = """<html> | |
<head></head> | |
<body>""" + html_filea + """<br>""" + html_fileb + """</body> | |
</html>""" | |
f.write(message) | |
f.close() | |
webbrowser.open_new_tab('index.html') | |
main(city, hotel) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment