from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
import pandas as pd
import numpy as np

sid = SentimentIntensityAnalyzer()

# Replace #'s with path of file with tweets
df1 = pd.read_excel(sheet_name="Results", io="##########")
for index, row in df1.iterrows():
    sentence = row["Tweet"]
    day = row["Date"]
    language = row["Language"]

    result = str(sid.polarity_scores(sentence))
    index = result.find('compound')
    resultclean = result[index:]
    resultcleanclean = resultclean.replace("compound': ","")
    resultsupercleanclean = resultcleanclean.replace("}","")

    if float(resultcleancleanclean) < 0 :
        label = 'Negative'

    if float(resultcleancleanclean) > 0 :
        label = 'Positive'

    if float(resultcleancleanclean) == 0.0 :
        label = 'Neutral'

    input1 = [sentence]
    input2 = [label]
    input3 = [day]
    input4 = [language]
    input5 = [float(resultcleancleanclean)]

    df = pd.DataFrame(list(zip(input1, input4, input3, input2, input5)))
    
# Replace #'s with path of destination file
    with pd.ExcelWriter("##########", mode='a', engine = "openpyxl", if_sheet_exists = "overlay") as writer:
        df.to_excel(writer, index = False, header = False, startrow = writer.sheets["Results"].max_row, sheet_name="Results")

print("Done")


    

