import os

def create_project_dir(directory):
    if not os.path.exists(directory):
        print('creating direction ' + directory)
        os.makedirs(directory)

def write_file(path, data):
    f = open(path, 'w')
    f.write(data)
    f.close()

def create_data_files(project_name, base_url):
    queue = project_name + '/queue.txt'
    crawled = project_name + '/crawled.txt'
    if not os.path.isfile(queue):
        write_file(queue, base_url)
    if not os.path.isfile(crawled):
        write_file(crawled, '')


def append_to_file(path, data):
    with open(path, 'a') as file:
        file.write(data + '\n')

def delete_file_contentd(path):
    with open(path, 'w'):
        pass

def file_to_set(file_name):
    result = set()
    with open(file_name, 'rt') as f:
        for line in f:
            result.add(line.replace('\n', ''))
        return result

def set_to_filr(links, file):
    delete_file_contentd(file)
    for link in sorted(links):
        append_to_file(file, link)
#create_data_files('Project', 'https://news.google.com/?hl=en-US&gl=US&ceid=US:en')
