def imdb_link_get_by_url(imdb_id):
    try:
        movie_name = ia.get_movie(
            imdb_id
        )  #using imdbpy api and given imdb_id extracts movie_name and
        movie_year = movie_name['year']  #release year
    except:
        log_maker.print2("Couldn't extract info from imdb")
        movie_name = "Couldn't extract info from imdb"
        movie_year = "Couldn't extract info from imdb"
    imdb_link = "http://www.imdb.com/title/tt" + imdb_id + "/"  #imdb link
    #log_maker.print2(movie_name,movie_year,imdb_link)
    return (movie_name, movie_year, imdb_link)
def Cleaner():
    #Just some housekeeping to keep the logs file in a managable size
    with open("logs", "w",
              encoding='utf-8') as f:  #About every month in flushes the logs
        f.write(
            "#####################################\n#####################################\n"
        )
    log_maker.print2("Flushed logs")
    with open("cleaner", "w", encoding='utf-8') as f:
        f.write("value=")
        f.write(str(0))
    main()
    return
def imdb_link_get_by_event_name(movie_name):
    if movie_name == 0:  #Queue imdb search, if no result found from given movie_name return 0
        return (0, 0)
    if movie_name == "":  #checks if movie name is none
        log_maker.print2("Couldn't extract usable movie name")
        return (0, 0)
    s_result = ia.search_movie(str(movie_name), results=1)
    if not s_result:  #checks if imdbpy didn't find any results with the name given
        log_maker.print2(
            "Couldn't find a match in imdb using the given movie name: " +
            movie_name)
        return (0, 0)
    else:
        for item in s_result:
            [imdb_name,
             imdb_id] = (item['long imdb canonical title'], item.movieID)
    return (imdb_name, imdb_id)
def Handler():
    with open("logs", "a", encoding='utf-8') as f:
        f.write(
            "#####################################\n#####################################\n"
        )
        f.close()
    file = open("cleaner", "r", encoding='utf-8')
    k = str(file.read(10))
    k = k.split('=')[1]
    k = int(k)
    file.close()
    main()
    k = k + 1
    if k > 30:
        Cleaner()
    with open("cleaner", "w", encoding='utf-8') as f:
        f.write("value=")
        f.write(str(k))
        f.close()
    log_maker.print2("Done,waiting 24h to start next circle")
def Strike_notifier(event_url, team_name, team_email):
    if SENDSTRIKE:
        #sends the emails and stuff
        info = "MAIL BODY\n"
        port = 465  # For SSL
        smtp_server = "smtp.gmail.com"
        subject = 'Subject'
        message = 'Subject:{}\n\n'.format(subject) + info + event_url
        log_maker.print2("Found strike " + team_name + " sending email to " +
                         team_email)
        context = ssl.create_default_context()
        with smtplib.SMTP_SSL(smtp_server, port, context=context) as server:
            server.login(EMAIL, PASS)
            if team_email != "":
                server.sendmail(EMAIL, team_email, message.encode("utf8"))
                server.close()
            else:
                message = message + "\nERROR MESSAGE?"
                server.sendmail(EMAIL, "YOUR [email protected]",
                                message.encode("utf8"))
                server.close()
def main():
    EMPTY_LOG_FINDER = "test"  #finds empty log cell(if it's empty end function because there are no more teams left to check)
    i = 2
    while EMPTY_LOG_FINDER != "":
        [
            team_name, events_url, last_id, team_name_next, number_of_strikes,
            team_email
        ] = sheets.SheetDataFetcher(i)  #Fetches from sheets team name etc.
        log_maker.print2("Doing " + team_name)  ######################
        event_ids = Events(events_url)
        new_strikes = 0
        for event_id in event_ids:  #adds new strikes to a team if they didn't add an imdb link to their event
            if event_id != last_id:
                strikes = fb_event_handler.per_event_handler(
                    event_id, team_name, team_email)
                new_strikes = int(new_strikes) + int(strikes)
            else:
                strikes = int(number_of_strikes) + int(new_strikes)
                sheets.LastEvent(i, event_ids[0], strikes)
                break
        i += 1
        EMPTY_LOG_FINDER = team_name_next  #Repeats stuffs for each "team"
Example #7
0
def SheetsNewEntry(movie_name,movie_year,team_name,event_date,imdb_link,event_url,lenght):
    if lenght > 1:  ##checks if event description has more than one imdb links 
        event_url = event_url + movie_name ##this is done to avoid conflicts on the following checks
    try:
        ##checks if movie was screened recently
        sheet = client.open("Auth Movies").sheet1
        movies_list = sheet.col_values(1)
        movie_name = str(movie_name)+ " ("+str(movie_year)+")"
        if movie_name in movies_list:
            i = movies_list.index(movie_name)
            i = i + 1  
            month1,year1 = normalize(str(event_date))   
            month2,year2 = normalize (str(sheet.cell(i,3).value))   
            event_date_norm = str(month1) + str(year1)
            found_event_date = str(month2) + str(year2)
            print (found_event_date,event_date_norm)
            if event_date_norm != found_event_date:
                d0 = date(int(year2), int(month2), 1)
                d1 = date(int(year1), int(month1), 1)
                delta = d1 - d0
                print(delta.days)
                if delta.days < DAYSAFTERLASTSCREENING :
                    conflict_url = str(sheet.cell(i,5).value)
                    sheet1 = client.open("EventCrawler").sheet1
                    teams_names = sheet1.col_values(1)
                    i = teams_names.index(team_name)
                    i = i + 1  
                    team_email = sheet1.cell(i, 5).value
                    Bot_Notifier.Conflict_notifier(event_url,conflict_url,team_name,team_email)
        event_list = sheet.col_values(5)                                                 #Reads the whole fb event column
        if event_url in event_list: #checks if event already exists in the spreadsheet
            i = event_list.index(event_url)
            i = i + 1                                                                    #gets row number
            team_name_old = sheet.cell(i, 2).value 
            if team_name in team_name_old:
                log_maker.print2 ("Turns out it was just a duplicate,either there were no new events or something might have gone wrong")
            else :
                log_maker.print2 ("Turns out it's a collaboration between "+str(team_name_old)+" & "+str(team_name))
                sheet.update_cell(i, 2, str(team_name_old)+" & "+str(team_name))         #adds collab if team's name doesn't already exist in said row
            return 
        else:
            log_maker.print2("Successfully added new entry to sheets:"+" " +str(movie_name)+" "+str(movie_year)+" "+str(team_name)+" "+str(event_date))          ################
            values = [movie_name,team_name,event_date,imdb_link,event_url]
            sheet.insert_row(values, index=3, value_input_option='RAW')
    except:
        log_maker.print2("Couldn't access Google sheets")
def imdb_alternative(event_name, event_date, event_url, team_name):
    movie_name1 = WordSearch1(
        event_name
    )  #Handles things when no imdb link was found in the event desc, circles through the different WordSearch methods
    [imdb_name, imdb_id] = imdb_link_get_by_event_name(
        movie_name1
    )  #search IMDB API for the first movie and get imdb_name1 or no result
    if imdb_name != 0:
        log_maker.print2("Found movie name " + imdb_name +
                         " in event name using WordSearch1")  ###############
        [movie_name, movie_year, imdb_link] = imdb_link_get_by_url(imdb_id)
        sheets.WordSearchSheetAdd(movie_name, movie_year, team_name,
                                  event_date, imdb_link, event_url)
    elif imdb_name == 0:
        movie_name2 = WordSearch2(event_name)
        [imdb_name, imdb_id] = imdb_link_get_by_event_name(movie_name2)
        if imdb_name != 0:
            log_maker.print2(
                "Found movie name " + imdb_name +
                " in event name using WordSearch2")  ###############
            [movie_name, movie_year, imdb_link] = imdb_link_get_by_url(imdb_id)
            sheets.WordSearchSheetAdd(movie_name, movie_year, team_name,
                                      event_date, imdb_link, event_url)
        elif imdb_name == 0:
            movie_name3 = WordSearch3(event_name)
            [imdb_name, imdb_id] = imdb_link_get_by_event_name(movie_name3)
            if imdb_name != 0:
                log_maker.print2(
                    "Found movie name " + imdb_name +
                    " in event name using WordSearch3")  ###############
                [movie_name, movie_year,
                 imdb_link] = imdb_link_get_by_url(imdb_id)
                sheets.WordSearchSheetAdd(movie_name, movie_year, team_name,
                                          event_date, imdb_link, event_url)
            elif imdb_name == 0:
                [movie_name, movie_year, imdb_link
                 ] = ["Couldn't extract movie name", "UKNOWN_YEAR", "UKNOWN"]
                sheets.WordSearchSheetAdd(movie_name, movie_year, team_name,
                                          event_date, imdb_link, event_url)
                log_maker.print2(
                    "Couldn't find movie.Sad MAYDAY MAYDAY MAYDAY")
Example #9
0
def LastEvent(i,last_id,strikes):
    sheet = client.open("EventCrawler").sheet1                                           #updates the event url which was the latest as of program end
    sheet.update_cell(i, 3, str(last_id))
    sheet.update_cell(i, 4, str(strikes))
    log_maker.print2("Successfully updated last event name in sheets: "+last_id)