-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
66 lines (48 loc) · 1.94 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
"""main.py: Combines the PDF analysis, image generation and Instagram posting
mechanisms.
To test this locally, do `flask --app main run` and then POST
a link to a PDF via Postman, for example. """
from flask import Flask, request
import os
from pathlib import Path
from dotenv import load_dotenv
from instagrapi import Client
# from src.app import summarize_text
from src.image_generation import generate_images
from src.instagram_posting import post_carousel
from src.pdf_analysis import analyze_pdf
dotenv_path = Path(".env")
load_dotenv(dotenv_path=dotenv_path)
instagram_username = os.getenv("INSTAGRAM_USERNAME")
instagram_password = os.getenv("INSTAGRAM_PASSWORD")
URL = "https://www.bundestag.de/ausschuesse"
app = Flask(__name__)
@app.route("/", methods=["POST"])
def index():
link = request.form["pdf_url"]
client = Client()
client.login(username=instagram_username, password=instagram_password)
pdf_content = analyze_pdf(link)
if not pdf_content:
return ("", 500)
file_paths = generate_images(link, pdf_content)
if not file_paths:
return ("", 500)
caption = "" if not pdf_content["Ergänzungsmitteilung"] else "[Ergänzung] "
caption += f"[{pdf_content['Ausschuss']}] "
caption += f"[{pdf_content['Sitzungsnummer']}. Sitzung am {pdf_content['Sitzungsdatum']}] "
caption += f"[{pdf_content['Wahlperiode']}. Wahlperiode]"
# TODO: Count tagesordnungen per party?
# TODO: Shorten it automaticcaly? (Instagram maximal caption length: 2,200 characters)
# Do post on instagram
post_carousel(
client=client,
image_paths=file_paths,
caption=caption,
)
# Funny idea: Let LLM "spice up" the caption haha (but stick to the infrmation)
# Could do "slang days": monday: like a doctor tuesday: like a comupter nerd, blabla
# Logout from the Instagrapi client
client.logout()
return ("", 200)