def __init__(self): self.drugs = utils.load_drug_file() self.emoticons_to_type, self.type_to_emoticons = load_emoticon_file() self.schizo_words = load_schizo_file() self.porter = nltk.PorterStemmer() self.lmtzr = WordNetLemmatizer() self.emoticon_regexes = emr = {} for etype, emotes in self.type_to_emoticons.items(): emotes_str = "|".join([re.escape(e) for e in emotes]) regex = re.compile( "({0})".format(emotes_str)) emr[etype] = regex
def main(): # should change these to use a dynamically loaded file drugs = utils.load_drug_file() creds = utils.load_credentials_file() api_client = twython.Twython(*creds) drugs_to_search = ['"' + el + '"' if el.find(" ") >= 0 else el for el in drugs["risperidone"]] query = utils.url_encode(" OR ".join(drugs_to_search)) print(query) # additional parameters can control date range, guessed language, etc. results = api_client.search(q=query, count=100, lang="en") for result in results["statuses"]: print(result["text"]) print("") tl = get_timeline(api_client, "1265683232") tlt = [t["text"] for t in tl] print(tlt)