<file_sep>#!/bin/python

from bs4 import BeautifulSoup
import pandas as pd
import requests
import re
import sys
import time


url = sys.argv[1]

response = requests.get(url)

soup = BeautifulSoup(response.text, 'html.parser')

# ======== parsing URL for title ========
url_list = url.split('?')

urlSansQuery = url_list[0]

if urlSansQuery[-1] == '/':
    urlSansQuery = urlSansQuery[-1]

base_url_list = urlSansQuery.split('/')

url_ending = base_url_list[-1]

# ======== tags ========
t_tags = soup.find_all('title')

p_tags = soup.find_all('p')

# ======== file name ========
filename = f'{url_ending}-text.txt'

# ======== writing file ========
with open(filename, 'w') as f:
    f.write('-------- title text --------')
    f.write('\n')
    f.write('\n')
    for t in t_tags:
        f.write(t.text)
        f.write('\n')

    f.write('\n')
    f.write('\n')
    f.write('-------- article text --------')
    f.write('\n')
    f.write('\n')
    for p in p_tags:
        f.write(p.text)
        f.write('\n')
        f.write('\n')

f.close()