Skip to content

Instantly share code, notes, and snippets.

from sklearn.neural_network import MLPRegressor
from nltk.stem.lancaster import LancasterStemmer
from nltk.corpus import stopwords
import re
from operator import itemgetter
def prepareSentence(s):
stemmer = LancasterStemmer()
ignore_words = set(stopwords.words('english'))
regpattern = re.compile('[\W_]+" "')
import tweepy
import json
import datetime
import time
# API access details - get yours from Twitter
access_token = "********************"
access_token_secret = "********************"
consumer_key = "********************"
consumer_secret = "********************"
import glob
import pathlib
import os
import json
#Make sure we're in the same dir that has the downloaded JSON twitter data
os.chdir('/home/username/twitter_data')
tweets = []
words = []
for tweet in tweets:
words.extend(prepareSentence(tweet["text"]))
distinct_words = set(words)
lower_threshold = 10
upper_threshold = 350
counts = []
@Joshuaek
Joshuaek / toBOW.py
Last active November 6, 2017 20:58
def toBOW(sentance, words):
bag = []
for word in words:
bag.append(1) if word in sentance else bag.append(0)
return bag
inputs = []
outputs = []
for tweet in tweets:
sentence = prepareSentence(tweet["text"])
# create our bag of words array
bag = toBOW(sentence, final_words)
inputs.append(bag)
#Calculate a score, 1 if any engagement, 0 if none
import feedparser
potential_posts = {}
for url in ['https://feeds.feedburner.com/CoinDesk', 'http://newsrss.bbc.co.uk/rss/newsonline_uk_edition/technology/rss.xml','http://i.perezhilton.com/?feed=rss2']:
feed = feedparser.parse(url)
for article in feed.entries:
sentence = prepareSentence(article.title)
bag = toBOW(sentence, final_words)
potential_posts[article.title] = nnet.predict([bag])[0]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import os
import sys
import argparse
import fnmatch
import logging
import papermill as pm
from datetime import datetime
import time
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.