-
Notifications
You must be signed in to change notification settings - Fork 2
/
reddit-csv-udemy.py
23 lines (18 loc) · 957 Bytes
/
reddit-csv-udemy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import csv
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from tabledef import *
# Initialise Database
engine = create_engine('sqlite:///courses.db')
Session = sessionmaker(bind=engine)
session = Session()
for line in open("reddit.csv"):
udemy_url = line.strip()
if session.query(Course).filter(Course.udemy_url == udemy_url).first() is not None:
print("udemy url already added @ row", session.query(Course).filter(Course.udemy_url == udemy_url).first().id ,". skipping to next...")
else:
course = Course(bitly_url=None, post_date="reddit", status="udemy url found", expanded_url=None, udemy_url=udemy_url, checkout_url=None, course_name=None, discounted_price=None, original_price=None, date_last_checked=None, remarks=None)
print("successfully added for udemy_url:", udemy_url)
session.add(course)
session.commit()
print("reddit import completed.")