dialog


In [1]:
from pyquery import PyQuery

In [2]:
import requests

In [3]:
import got

In [4]:
headers  = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/532.31'}
url = 'https://twitter.com/i/realDonaldTrump/conversation/935340092583006208?include_available_features=1&include_entities=1&max_position=&reset_error_state=false'
res = requests.get(url)
res.json()
items = PyQuery(res.json()['items_html'])('ol.stream-items')
for item in items: print item
https://twitter.com/i/activity/retweeted_popup?id=912741016947609600 https://twitter.com/i/activity/favorited_popup?id=912741016947609600

In [9]:
import random

In [6]:
import pdb

In [10]:
def fetch_activities(tweet_id):
	retusers = []
	favorusers = []
	re_url = 'https://twitter.com/i/activity/retweeted_popup?id=%s'%(tweet_id)
	favor_url = 'https://twitter.com/i/activity/favorited_popup?id=%s'%(tweet_id)
	headers = {
			'Host':"twitter.com",
			'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.%s'%(random.randint(0,999)),
			'Accept':"application/json, text/javascript, */*; q=0.01",
			'Accept-Language':"de,en-US;q=0.7,en;q=0.3",
			'X-Requested-With':"XMLHttpRequest",
			'Referer':'https://twitter.com/',
			'Connection':"keep-alive",
		}
	pdb.set_trace()
	re_users = PyQuery(re_url,headers=headers)('ol.activity-popup-users')
	for re_user in re_users('div.account'):
		retusers.append(re_user.attr('data-screen-name'))
	favor_users = PyQuery(favor_url,headers=headers)('ol.activity-popup-users')
	for favor_user in favor_users('div.account'):
		favorusers.append(favor_user.attr('data-screen-name'))
		
	return retusers,favorusers
fetch_activities(912741016947609600)

In [ ]:
ol.activity-popup-users dropdown-threshold | div.account  js-actionable-user js-profile-popup-actionable |data-screen-name

In [ ]:
htmlUsers

In [ ]:
dialog = got.manager.DialogManager.getDialogById(935433391654051840)

In [ ]:
dialog['original'].__dict__

In [ ]:

tweet.__dict__
tweetCriteria = got.manager.TweetCriteria().setQuerySearch('ack linux').setTweetType('f=news').setMaxTweets(40) tweets = got.manager.TweetManager.getTweets(tweetCriteria)
len(tweets)
for i in tweets: print i.__dict__
ancestor has-replies original-permalink-page descendant permalink-descendant-tweet

tweet

tweetPQ('p.js-tweet-text a').filter(lambda i: PyQuery(this).attr('data-expanded-url') != None)

In [ ]:

html = requests.get('https://twitter.com/GailDavvis/status/935342611065339907',headers=headers) doc = PyQuery(html.content) tweetPQ = PyQuery(doc)
def fetch_entities(tweetPQ): hashtags = [] urls = [] for url in tweetPQ('p.js-tweet-text a'): d = dict(url.items()) if d['class'] == 'twitter-timeline-link': urls.append({'href':d['href'],'expanded_url':d['data-expanded-url']}) if d['href'].startswith('/hashtag/'): hashtags.append(d['href'].split('?')[0].split('/')[-1]) tweetPQ('p.js-tweet-text a.twitter-timeline-link').remove() return hashtags,urls
tweetPQ('p.js-tweet-text a')
fetch_entities(tweetPQ)
tweetPQ('p.js-tweet-text a')