
import os
import requests
import shutil
from bs4 import BeautifulSoup
from datetime import datetime
from .s3 import upload_file


def current():
    



if __name__ == "__main__":
    current()

url = 'http://intelligentlifecomics.com'
    req = requests.get(url)

    if(req.status_code != 200):
        return

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

    date_str = soup.find(id="comic-date").get_text().strip()
    date_object = datetime.strptime(date_str, '%B %d, %Y')
    date_fmt = date_object.strftime('%Y-%m-%d')
    file_path = "temp/%s.gif" % date_fmt

    img_url = soup.find(id='comicpanel').find('img').get('src')
    r = requests.get(img_url, stream=True)
    if r.status_code == 200:
        with open(file_path, 'wb') as f:
            r.raw.decode_content = True
            shutil.copyfileobj(r.raw, f)

    upload_file(file_path)
    os.remove(file_path)