import os, sys from datetime import datetime from dateutil import relativedelta from atproto import Client, client_utils sys.path.append('/var/www/digisnaxx.ado/scrapers') import dtss dtss.getReady() from time import sleep from pprint import pprint as ppr import pytz from contracts.models import Contract from events.digitools import getBrowser, createURL, createBasicEvent, getSource tz = pytz.timezone("US/Central") # USERNAME = "dreamfreely.org" # PASSWORD = "gU):3-BA]DaK[_K$DHmI" USERNAME = "digisnaxx.bsky.social" PASSWORD = "xv57-clj3-sjpw-iz5o" client = Client() client.login(USERNAME, PASSWORD) contracts = Contract.objects.all().order_by('-pub_date')[35:] for c in contracts: URL = "https://www.digisnaxx.com/contract/" + str(c.id) URL_TITLE = "DoD Contract {0}" URL_DESCRIPTION = "DigiSnaxx Link to DoD Contract {0}" try: if len(c.contract_value) > 4 and c.company != None: POST_TEXT = "\n\n{0} / {1}\n\nCompany: {2}\n\n{3}\n\nNAICS Code: {4}".format(c.us_dept, c.us_dept_sub_tier, c.company.name, c.contract_value, c.naics_code) ALT_TEXT = " ID {0}. For the {1} sub-tier {2}. Contract awarded to {3}.".format(c.notice_id, c.us_dept, c.us_dept_sub_tier, c.company.name) elif len(c.contract_value) == 4 and c.company != None: POST_TEXT = "\n\n{0} / {1}\n\nCompany: {2}\n\nNAICS Code: {3}".format(c.us_dept, c.us_dept_sub_tier, c.company.name, c.naics_code) ALT_TEXT = " ID {0}. For the {1} sub-tier {2}. Contract awarded to {3}. {4}".format(c.notice_id, c.us_dept, c.us_dept_sub_tier, c.company.name, c.naics_code) elif len(c.contract_value) > 4 and c.company == None: POST_TEXT = "\n\n{0} / {1}\n\n{2}\n\nNAICS Code: {3}".format(c.us_dept, c.us_dept_sub_tier, c.contract_value, c.naics_code) ALT_TEXT = " ID {0}. For the {1} sub-tier {2}. {3}. There is no company.".format(c.notice_id, c.us_dept, c.us_dept_sub_tier, c.naics_code) elif len(c.contract_value) == 4 and c.company == None: POST_TEXT = "\n\n{0} / {1}\n\nNAICS Code: {2}".format(c.us_dept, c.us_dept_sub_tier, c.naics_code) ALT_TEXT = "ID {0}. For the {1} sub-tier {2}. There is no company.".format(c.notice_id, c.us_dept, c.us_dept_sub_tier) else: continue text = client_utils.TextBuilder().tag("#DoDContracts ", "DoDContracts").tag("#"+c.notice_id[:16], c.notice_id[:16],).text(POST_TEXT + "\n\n").link(URL, URL) print(POST_TEXT) ppr(c) client.send_post(text=text) sleep(25) except Exception as e: print(c.notice_id) print("Error: ", e) # feed = client.get_author_feed(USERNAME, limit = 100)