import os
import sys
from app.libraries.setup import Setup
from app.libraries.database import Database
from app.libraries.domainblocks import DomainBlocks
from mastodon import Mastodon

# main

if __name__ == '__main__':

    setup = Setup()

    db = Database()

    blocker = DomainBlocks()

    mastodon = Mastodon(
        access_token = setup.mastodon_app_token,
        api_base_url= setup.mastodon_hostname
        )

    soft_list = 'software.txt'

    soft_file = open(soft_list, 'r')

    Lines = soft_file.readlines()
    
    for softline in Lines:

        split_char = ' '

        software = softline.partition(split_char)[0]
        
        private_comment = softline.partition(split_char)[2]

        public_comment = softline.partition(split_char)[2]

        print(f'checking software {software}...')

        servers_list = db.get_servers(software)

        for server in servers_list:

            blocker.domain_blocks_create(server, private_comment, public_comment)



