import csv import os import requests def seed_with_csv(): print("reading csv...") file_path = os.path.join(os.path.dirname(__file__), "feeds.csv") has_written = False with open(file_path, mode="r", newline="", encoding="utf-8") as f: reader = csv.reader(f) # If your CSV has a header row, uncomment the next line to skip it # next(reader, None) for row in reader: print("reading row...") # Ensure the row has exactly two columns to avoid errors if len(row) == 2: try: res = requests.post("http://ploughshares.nixc.us/api/source", headers={ "Content-Type": "application/json" }, json={ "title":row[0], "link":row[1], "type":"Google Alert", }) if "error" not in res.json(): has_written = True except Exception as e: print(e) else: print("row has incorrect length.") return has_written if __name__ == "__main__": seed_with_csv()