Skip to content

Commit 432de20

Browse files
committed
fixed add to db + login check
1 parent da24b9b commit 432de20

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

instagram_feed.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ def insert_event_to_db(event_data, club_ig, post_url):
9191
conn = psycopg2.connect(os.getenv("SUPABASE_DB_URL"))
9292
cur = conn.cursor()
9393
query = """
94-
INSERT INTO events (club_ig, event_name, start_time, end_time, location, post_url)
95-
VALUES (%s, %s, %s, %s, %s, %s)
94+
INSERT INTO events (club_ig, event_name, date, start_time, end_time, location, post_url)
95+
VALUES (%s, %s, %s, %s, %s, %s, %s)
9696
ON CONFLICT DO NOTHING;
9797
"""
9898
cur.execute(query, (
9999
club_ig,
100-
event_data["event_name"],
100+
event_data["name"],
101+
event_data["date"],
101102
event_data["start_time"],
102103
event_data["end_time"],
103104
event_data["location"],
@@ -120,9 +121,9 @@ def process_recent_feed(cutoff=datetime.now(timezone.utc) - timedelta(days=1)):
120121
print(f"Caption: {post.caption[:100]}...")
121122
event_data = parse_caption_for_event(post.caption)
122123
post_url = f"https://www.instagram.com/p/{post.shortcode}/"
123-
update_event_csv(event_data, post.owner_username, post_url)
124-
if insert_event_to_db(event_data, post.owner_username, post_url):
125-
events_added += 1
124+
if update_event_csv(event_data, post.owner_username, post_url):
125+
if insert_event_to_db(event_data, post.owner_username, post_url):
126+
events_added += 1
126127
else:
127128
print("No caption found, skipping...")
128129

@@ -132,17 +133,22 @@ def process_recent_feed(cutoff=datetime.now(timezone.utc) - timedelta(days=1)):
132133

133134
def session():
134135
L = Instaloader()
135-
L.load_session(
136-
USERNAME,
137-
{
138-
"csrftoken": CSRFTOKEN,
139-
"sessionid": SESSIONID,
140-
"ds_user_id": DS_USER_ID,
141-
"mid": MID,
142-
"ig_did": IG_DID,
143-
},
144-
)
145-
return L
136+
try:
137+
L.load_session(
138+
USERNAME,
139+
{
140+
"csrftoken": CSRFTOKEN,
141+
"sessionid": SESSIONID,
142+
"ds_user_id": DS_USER_ID,
143+
"mid": MID,
144+
"ig_did": IG_DID,
145+
},
146+
)
147+
print("Successfully logged in")
148+
return L
149+
except Exception as e:
150+
print(f"Failed to load session: {e}")
151+
raise
146152

147153

148154
if __name__ == "__main__":

0 commit comments

Comments
 (0)