fixed web layout

This commit is contained in:
maru21 2024-11-08 21:57:01 +01:00
parent a6b5e560fb
commit 52f1565772
4 changed files with 25 additions and 17 deletions

3
.gitignore vendored
View File

@ -176,4 +176,5 @@ cython_debug/
*.json *.json
*.pdf *.pdf
data/* data/*
*.html

View File

@ -6,6 +6,8 @@ import os
from webSimple import generate_pdf_list_html from webSimple import generate_pdf_list_html
from email_pdf_downloader import read_emails from email_pdf_downloader import read_emails
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
def run_daemon(): def run_daemon():
while True: while True:
try: try:
@ -14,8 +16,8 @@ def run_daemon():
except Exception as e: except Exception as e:
logging.error(f"An error occurred: {e}") logging.error(f"An error occurred: {e}")
directory = '/scrapy/amznMailConverter/data' directory = SCRIPT_DIR+'/data'
output_file = os.path.join(directory, "/scrapy/amznMailConverter/index.html") output_file = os.path.join(directory, SCRIPT_DIR+"/index.html")
generate_pdf_list_html(directory, output_file) generate_pdf_list_html(directory, output_file)
time.sleep(60) # Sleep for 1 minute between checks time.sleep(60) # Sleep for 1 minute between checks

View File

@ -20,15 +20,15 @@ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
def get_credentials(): def get_credentials():
creds = None creds = None
if os.path.exists('/scrapy/amznMailConverter/token.json'): if os.path.exists(SCRIPT_DIR+'/token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES) creds = Credentials.from_authorized_user_file(SCRIPT_DIR+'/token.json', SCOPES)
if not creds or not creds.valid: if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token: if creds and creds.expired and creds.refresh_token:
creds.refresh(Request()) creds.refresh(Request())
else: else:
flow = InstalledAppFlow.from_client_secrets_file('/scrapy/amznMailConverter/credentials.json', SCOPES) flow = InstalledAppFlow.from_client_secrets_file(SCRIPT_DIR+'/credentials.json', SCOPES)
creds = flow.run_local_server(port=0) creds = flow.run_local_server(port=0)
with open('/scrapy/amznMailConverter/token.json', 'w') as token: with open(SCRIPT_DIR+'/token.json', 'w') as token:
token.write(creds.to_json()) token.write(creds.to_json())
return creds return creds

View File

@ -1,7 +1,6 @@
#!/scrapy/venvs/amznMailConverter/bin/python #!/scrapy/venvs/amznMailConverter/bin/python
import os import os
from datetime import datetime from datetime import datetime
def generate_pdf_list_html(directory, output_file="pdf_list.html"): def generate_pdf_list_html(directory, output_file="pdf_list.html"):
@ -14,24 +13,26 @@ def generate_pdf_list_html(directory, output_file="pdf_list.html"):
# Get the current timestamp # Get the current timestamp
generation_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") generation_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# HTML content with dark and blue-themed Material Design styling # HTML content with updated styling
html_content = f'''<html> html_content = f'''<html>
<head> <head>
<title>PDF Files</title> <title>PDF Files</title>
<style> <style>
body {{ font-family: Arial, sans-serif; background-color: #121212; color: #e0e0e0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }} body {{ font-family: "Courier New", Courier, monospace; background-color: #0d1b2a; color: #e0e0e0; margin: 0; padding: 100px; }}
.container {{ max-width: 600px; background: #1e1e1e; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5); border-radius: 8px; padding: 20px; text-align: center; }} .container {{ max-width: 800px; background: #1b2631; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.5); border-radius: 12px; padding: 30px; margin: auto; margin-top: 40px; }}
h2 {{ color: #bb86fc; font-size: 24px; margin-bottom: 20px; }} h2 {{ color: #00bfff; font-size: 28px; margin-bottom: 10px; }}
.separator {{ border-top: 2px solid #00bfff; margin-bottom: 50px; }}
ul {{ list-style-type: none; padding: 0; }} ul {{ list-style-type: none; padding: 0; }}
li {{ margin: 10px 0; }} li {{ margin: 15px 0; }}
a {{ text-decoration: none; color: #03dac6; font-weight: bold; padding: 10px 15px; border-radius: 5px; transition: background-color 0.2s ease; }} a {{ text-decoration: none; color: #00bfff; font-weight: bold; padding: 10px 15px; border-radius: 5px; transition: background-color 0.2s ease; }}
a:hover {{ background-color: #333; color: #bb86fc; }} a:hover {{ background-color: #005f7f; color: #ffffff; }}
.footer {{ margin-top: 20px; font-size: 12px; color: #666; }} .footer {{ margin-top: 60px; font-size: 12px; color: #bbb; }}
</style> </style>
</head> </head>
<body> <body>
<div class="container"> <div class="container">
<h2>Available PDF Files for Download</h2> <h2>Available PDF Files for Download</h2>
<div class="separator"></div>
<ul>''' <ul>'''
for name in file_list: for name in file_list:
@ -51,4 +52,8 @@ def generate_pdf_list_html(directory, output_file="pdf_list.html"):
except Exception as e: except Exception as e:
print(f"An error occurred: {e}") print(f"An error occurred: {e}")
# Usage
if __name__ == "__main__":
directory = 'amznMailConverter/data'
output_file = os.path.join(directory, "pdf_list.html")
generate_pdf_list_html(directory, output_file)