import pandas as pd 
import re

media_polarity = {
        "247sports.com": "NA",
        "ABCNews": -1,
        "AirforceTimes": "NA",
        "Alternet": -2,
        "American Free Press": "NA",
        "American Spectator": "NA",
        "amp.freep.com": "NA",
        "AOL News": "NA",
        "aol.sportingnews.com": "NA",
        "arkansasonline": -2,
        "ArmyTimes": "NA",
        "arstechnica.com": "NA",
        "ajc.com": -1,
        "Atlantic": -1,
        "augustachronicle.com": "NA",
        "AZCentral": 0,
        "Baltimore Sun": "NA",
        "Benzinga": "NA",
        "berkshireeagle.com": "NA",
        "Billboard": "NA",
        "Blaze": 2,
        "Bleacher Report": "NA",
        "blogs.barrons.com": "NA",
        "blogs.indystar.com": 0,
        "Bloomberg": -1,
        "Breitbart": 2,
        "Insider.com": 0,
        "BusinessWeek.com": "NA",
        "Bustle": -1,
        "Buzzfeed": -2,
        "CBSNews": -1,
        "cbssports.com": -1,
        "Central Maine News": "NA",
        "cherokeephoenix.org": "NA",
        "ChicagoTribune": 0,
        "CSMonitor": 0,
        "cincinnati.com": "NA",
        "cleveland.com": "NA",
        "CNBC": "NA",
        "CNET": 0,
        "CNN": -2,
        "CNSNews": 2,
        "colorlines.com": "NA",
        "Columbus Dispatch": "NA",
        "Conversation": "NA",
        "creators.com": "NA",
        "CSPAN": "NA",
        "DailyBeast": -2,
        "DailyCaller": 2,
        "DailyDot": -1,
        "DailyKos": -2,
        "DailySignal": 2,
        "Daily Source": "NA",
        "DallasNews": 0,
    "Deadspin": "NA",
    "E! Online": "NA", 
    "eater.com": "NA",
    "El Nuevo Dia": "NA",
        "elitedaily.com": "NA",
    "engadget": "NA",
    "Entertainment Weekly": "NA",
    "ESPN": "NA",
    "eurweb": "NA",
    "FactCheck": 0,
    "Fansided": "NA",
    "fark.com": "NA",
    "fayobserver.com": "NA",
    "FiveThirtyEight": 0,
    "Forbes": 0,
    "Fortune": 0,
    "FoxNews": 2,
    "Fox Sports": "NA",
    "Fusion": "NA",
    "Gawker": "NA",
    "gazettenet.com": "NA",
    "Gizmodo": -1,
    "globalpost.com": "NA",
    "gq.com": -1,
    "Grist": -1,
    "Guardian": -1,
    "Harper's Magazine": "NA",
    "Hartford Courant": "NA",
    "hollywoodlife.com": "NA",
    "HonululuAdvertiser": "NA",
    "HotAir": 1,
    "houstonchronicle": 0,
    "Hoy Chicago": "NA",
    "HuffPost": -2,
    "IBTimes": 0,
    "ign.com": "NA",
    "ihavenet.com": "NA",
    "Indian Country Today": "NA",
    "Infowars": 2,
    "Indiewire": "NA",
    "Inquirer": "NA",
    "Inquisitr": "NA",
    "Intercept": -2,
    "Investors": "NA",
    "Jezebel": -2,
    "LATimes": -1,
    "livescience.com": 0,
    "marinetimes.com": "NA",
    "Marketwatch": 0,
    "Mashable!": "NA",
    "media.oregonlive.com": "NA",
    "MiamiHerald": -1,
    "Mic": "NA",
    "Milwaukee Journal Sentinel": "NA",
    "MintPress News": "NA",
    "mlive.com": "NA",
    "Mongabay": "NA",
    "monstersandcritics": "NA",
    "MotherJones": -2,
    "mysanantonio.com": "NA",
    "National Catholic Register": "NA",
    "National Memo": "NA",
    "NationalReview": 2,
    "NavyTimes": "NA",
    "NBC": -1,
    "ncronline.org": "NA",
    "NYPost": 1,
    "NYTimes": -1,
    "NewYorker": -2,
    "newsblaze.com": "NA",
    "NewsBusters": 2,
    "Newsday": "NA",
    "Newsmax": 1,
    "newsone.com": -2,
    "Newsweek": 0,
    "newsy": 0,
    "nhgazette.com": "NA",
    "nj.com": "NA",
    "norwichbulletin.com": "NA",
    "NPR": -1,
    "Oan": 2,
    "observer.com": 0,
    "Omaha World-Herald": "NA",
    "opednews.com": "NA",
    "OpenSecrets": 0,
    "opposingviews.com": "NA",
    "OCRegister": 1,
    "OrlandoSentinel": "NA",
    "Parade": "NA",
    "patriot post": "NA",
    "PBS": 0,
    "PEOPLE.com": "NA",
    "pilotonline.com": "NA",
    "pitchfork.com": "NA",
    "Post-Gazette": 1,
    "PJMedia": 2,
    "Politico": -1,
    "polygon.com": "NA",
    "popmatters": "NA",
    "Post and Courier": "NA",
    "Press-Republican": "NA",
    "ProPublica": -1,
    "providencejournal.com": "NA",
    "Quartz": 0,
    "RawStory": -2,
    "Re/code": "NA",
    "RealClearPolitics": 0,
    "Reason.com": 1,
    "Red Herring": "NA",
    "RedState": 2,
    "Refinery29": -2,
    "Reuters": 0,
    "RollCall": 0,
    "RollingStone": -2,
    "rttnews": "NA",
    "rutlandherald.com": "NA",
    "Salon": -2,
    "SanDiegoUnionTribune": -1,
    "San Jose Mercury News": "NA",
    "Saturday Evening Post": "NA",
    "SB Nation": "NA",
    "Schwartzreport": "NA",
    "ScientificAmerican": -1,
    "Seattle Times": "NA",
    "sentinelsource.com": "NA",
    "SFChronicle": -1,
    "Slate": -2,
    "South Florida Sun-Sentinel": "NA",
    "St. Louis Post-Dispatch": "NA",
    "St.Paul Pioneer-Press": "NA",
    "Star Tribune": "NA",
    "Stars and Stripes" :"NA",
    "Stateline - News about state government and politics from The Pew Center on the States": "NA",
    "MSNBC": -2,
    "Taegan Goddard's Political Wire": "NA",
    "Talk Media News": "NA", 
    "Talking Points Memo": "NA",
    "Tampa Bay Times": "NA",
    "TechCrunch": "NA",
    "techradar.com": "NA",
    "BostonGlobe": -1,
    "BuffaloNews": "NA",
    "The Insider": "NA",
    "TheNation": -2,
    "NewReplublic": -2,
    "Onion": -1,
    "TheWeek": 0,
    "theroot.com": -1,
    "Time.com": -1,
    "TMZ": "NA",
    "townhall.com": 2,
    "Truthout": -1,
    "USNews": -1,
    "USAToday": 0,
    "VanityFair": -1,
    "variety.com": 0,
    "Verge": -1,
    "VICE": -2,
    "Vox": -2,
    "wSJ": 1,
    "WashingtonPost": -1,
    "wired": 0,
}

def f(row):
    for key in media_polarity.keys():
        key_search = key.lower()
        m = re.search(key_search, row['last_url'])
        if m is not None:
            return media_polarity[key]
    return "NA"


media_data = pd.read_csv("writers_plus_twitter_network_small2.csv")
media_data["polarity"] = media_data.apply(f, axis=1)

media_data.to_csv(path_or_buf="journalists_2019.csv", index = False)
