Created
January 21, 2023 23:00
-
-
Save jhubble/8a99aa3e05aa07696653f0fa00b134b0 to your computer and use it in GitHub Desktop.
Convert Delta Skymiles history HTML output to CSV
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
#!/usr/local/bin/python3 | |
# Save the html from Delta Skymiles account activity as "skymiles.html" | |
# Then run this python script | |
# It will output tab delimited output with date, description, miles, and details | |
# Will be sorted from oldest to newest | |
from bs4 import BeautifulSoup as bs | |
from bs4 import BeautifulSoup | |
import re | |
with open("skymiles.html") as fp: | |
soup = BeautifulSoup(fp, 'html.parser') | |
#prettyHTML = soup.prettify() #prettify the html | |
#print (prettyHTML) | |
def get_text(tag): | |
full_val = '' | |
for elem in tag: | |
full_val += elem.text | |
#full_val = full_val.replace("\n","") | |
full_val = full_val.strip() | |
full_val = re.sub("\s+"," ", full_val) | |
return full_val | |
arr = [] | |
for tag in soup.select('div.divAx > ul > li'): | |
#print(tag) | |
date = tag.select('.displayDateMonthYear') | |
full_date = get_text(date) | |
desc = get_text(tag.select('.headBar')) | |
miles = get_text(tag.select('.allTotal')) | |
detail = get_text(tag.select('.subDetailContainer')) | |
#print(">"+full_date) | |
#print (desc) | |
#print (miles) | |
#print (detail) | |
out = full_date+"\t"+miles+"\t"+desc+"\t"+detail | |
arr.insert(0,out) | |
#print("-------------------") | |
print ("\n".join(arr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment