本文整理汇总了Python中smarttypes.model.twitter_user.TwitterUser类的典型用法代码示例。如果您正苦于以下问题:Python TwitterUser类的具体用法?Python TwitterUser怎么用?Python TwitterUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TwitterUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user
def user(request):
if 'user_id' in request.params:
user_id = int(request.params['user_id'])
twitter_user = TwitterUser.get_by_id(user_id)
else:
screen_name = request.params['screen_name']
twitter_user = TwitterUser.by_screen_name(screen_name)
return {
'twitter_user':twitter_user,
}
示例2: get_igraph_g
def get_igraph_g(self):
from smarttypes.model.twitter_user import TwitterUser
from smarttypes.graphreduce.reduce_graph import get_igraph_graph
network = {}
for score, user_id in self.get_members():
user = TwitterUser.get_by_id(user_id, self.postgres_handle)
network[user.id] = set(user.following_ids)
g = get_igraph_graph(network)
pagerank = g.pagerank(damping=0.65)
both = zip(pagerank, g.vs["name"])
for x, y in sorted(both):
print x
print TwitterUser.get_by_id(y, self.postgres_handle).screen_name
示例3: complete_signin
def complete_signin(request_key, verifier, postgres_handle):
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
session = TwitterSession.get_by_request_key(request_key, postgres_handle)
if session.access_key:
#this happens if we get multiple same exact responses from twitter
#perhaps crazy clicking or back / forward browsing
credentials = TwitterCredentials.get_by_access_key(session.access_key, postgres_handle)
else:
auth.set_request_token(request_key, session.request_secret)
auth.get_access_token(verifier)
# may have signed up already
credentials = TwitterCredentials.get_by_access_key(auth.access_token.key, postgres_handle)
if not credentials:
credentials = TwitterCredentials.create(auth.access_token.key, auth.access_token.secret, postgres_handle)
session.access_key = credentials.access_key
if not credentials.twitter_user:
#probably don't have the user in our db yet
user = TwitterUser.upsert_from_api_user(credentials.api_handle.me(), postgres_handle)
credentials.twitter_id = user.id
credentials.save()
#email
screen_name = credentials.twitter_user.screen_name
email_utils.send_email('[email protected]', ['[email protected]'],
'%s signed up' % screen_name, 'smarttypes signup!')
return session.save()
示例4: logged_in_user
def logged_in_user(request):
screen_name = request.params['screen_name']
logged_in_user = TwitterUser.by_screen_name(screen_name)
return {
'logged_in_user':logged_in_user,
'TwitterGroup':TwitterGroup,
}
示例5: load_user_and_the_people_they_follow
def load_user_and_the_people_they_follow(creds, user_id, postgres_handle):
remaining_hits_threshold = 10
api_handle = creds.api_handle
root_user = creds.root_user
is_root_user = False
if root_user.id == user_id:
is_root_user = True
# if is_root_user and 'root_user.is_fake_user':
# return None
remaining_hits, reset_time = get_rate_limit_status(api_handle)
if remaining_hits < remaining_hits_threshold:
raise Exception("%s: remaining_hits less than threshold!" % root_user.screen_name)
try:
api_user = api_handle.get_user(user_id=user_id)
except TweepError, ex:
print "%s: api_handle.get_user(%s) got a TweepError %s" % (root_user.screen_name, user_id, ex)
if 'Sorry, that page does not exist' in str(ex) or 'User has been suspended' in str(ex):
print 'setting caused_an_error'
model_user = TwitterUser.get_by_id(user_id, postgres_handle)
if not model_user:
properties = {'id': user_id, 'screen_name': user_id}
model_user = TwitterUser(postgres_handle=postgres_handle, **properties)
model_user.save()
postgres_handle.connection.commit()
model_user.caused_an_error = datetime.now()
model_user.save()
postgres_handle.connection.commit()
return None
示例6: index
def index(req, session, postgres_handle):
root_user = None
if 'user_id' in req.params:
root_user = TwitterUser.get_by_id(req.params['user_id'], postgres_handle)
if not root_user:
root_user = TwitterUser.by_screen_name('SmartTypes', postgres_handle)
reduction = TwitterReduction.get_latest_reduction(root_user.id, postgres_handle)
if not reduction:
root_user = TwitterUser.by_screen_name('SmartTypes', postgres_handle)
reduction = TwitterReduction.get_latest_reduction(root_user.id, postgres_handle)
return {
'active_tab': 'social_map',
'template_path': 'social_map/index.html',
'root_user': root_user,
'reduction': reduction,
'num_groups': len(TwitterGroup.all_groups(reduction.id, postgres_handle)),
'users_with_a_reduction': TwitterReduction.get_users_with_a_reduction(postgres_handle),
}
示例7: get_user_reduction_counts
def get_user_reduction_counts(cls, postgres_handle):
from smarttypes.model.twitter_user import TwitterUser
return_users = []
qry = """
select root_user_id, count(root_user_id) as reduction_count
from twitter_reduction
group by root_user_id;
"""
for result in postgres_handle.execute_query(qry):
user = TwitterUser.get_by_id(result['root_user_id'], postgres_handle)
return_users.append((user, result['reduction_count']))
return return_users
示例8: get_users_with_a_reduction
def get_users_with_a_reduction(cls, postgres_handle):
from smarttypes.model.twitter_user import TwitterUser
return_users = []
qry = """
select distinct root_user_id
from twitter_reduction
order by root_user_id;
"""
for result in postgres_handle.execute_query(qry):
user = TwitterUser.get_by_id(result['root_user_id'], postgres_handle)
return_users.append(user)
return return_users
示例9: top_users
def top_users(self, num_users=20, just_ids=False):
from smarttypes.model.twitter_user import TwitterUser
return_list = []
score_user_id_tup_list = self.get_members()
for score, user_id in heapq.nlargest(num_users, score_user_id_tup_list):
if score:
add_this = (score, user_id)
if not just_ids: add_this = (score, TwitterUser.get_by_id(user_id, self.postgres_handle))
return_list.append(add_this)
else:
break
return return_list
示例10: community_features
def community_features(req, session, postgres_handle):
reduction = None
if req.path.split('/') > 3 and req.path.split('/')[3]: # path looks like '/social_map/community_features/something'
root_user = TwitterUser.by_screen_name(req.path.split('/')[3], postgres_handle)
if root_user:
reduction = TwitterReduction.get_latest_reduction(root_user.id, postgres_handle)
if not reduction and is_int(req.path.split('/')[3]):
reduction = TwitterReduction.get_by_id(req.path.split('/')[3], postgres_handle)
return {
'content_type': 'application/json',
'json':reduction.get_geojson_community_features() if reduction else [],
}
示例11: node_details
def node_details(req, session, postgres_handle):
twitter_user, in_links, out_links = None, [], []
if 'node_id' in req.params and 'reduction_id' in req.params:
reduction = TwitterReduction.get_by_id(req.params['reduction_id'], postgres_handle)
twitter_user = TwitterUser.get_by_id(req.params['node_id'], postgres_handle)
if twitter_user:
in_links, out_links = reduction.get_in_and_out_links_for_user(req.params['node_id'])
return {
'template_path': 'social_map/node_details.html',
'twitter_user': twitter_user,
'in_links':in_links,
'out_links':out_links,
}
示例12: load_user_and_the_people_they_follow
def load_user_and_the_people_they_follow(api_handle, screen_name):
print "Attempting to load %s" % screen_name
continue_or_exit(api_handle)
try:
api_user = api_handle.get_user(screen_name=screen_name)
except TweepError, ex:
print "Got a TweepError: %s." % ex
if str(ex) == "Not found":
print "Setting caused_an_error for %s " % screen_name
model_user = TwitterUser.by_screen_name(screen_name)
model_user.caused_an_error = datetime.now()
model_user.save()
return model_user
示例13: top_users
def top_users(self, num_users=20, just_ids=False):
from smarttypes.model.twitter_user import TwitterUser
return_list = []
i = 0
for score, user_id in sorted(self.scores_users, reverse=True):
if i <= num_users and score > .001:
add_this = (score, user_id)
if not just_ids: add_this = (score, TwitterUser.get_by_id(user_id))
return_list.append(add_this)
else:
break
i += 1
return return_list
示例14: pull_some_users
def pull_some_users(user_id):
postgres_handle = PostgresHandle(smarttypes.connection_string)
root_user = TwitterUser.get_by_id(user_id, postgres_handle)
if not root_user:
raise Exception('User ID: %s not in our DB!' % user_id)
if not root_user.credentials:
raise Exception('%s does not have api credentials!' % root_user.screen_name)
api_handle = root_user.credentials.api_handle
root_user = load_user_and_the_people_they_follow(api_handle, root_user.id, postgres_handle, is_root_user=True)
load_this_user_id = root_user.get_id_of_someone_in_my_network_to_load()
while load_this_user_id:
load_user_and_the_people_they_follow(api_handle, load_this_user_id, postgres_handle)
load_this_user_id = root_user.get_id_of_someone_in_my_network_to_load()
#load_this_user_id = None
print "Finshed loading all related users for %s!" % root_user.screen_name
示例15: load_network_from_the_db
def load_network_from_the_db(postgres_handle, distance):
network = OrderedDict()
def add_user_to_network(user):
network[user.id] = {}
network[user.id]['following_ids'] = set(user.following_ids)
#network[user.id]['following_ids'].add(user.id)
network[user.id]['follower_ids'] = set([])
network[user.id]['following_count'] = user.following_count
network[user.id]['followers_count'] = user.followers_count
twitter_user = TwitterUser.by_screen_name('SmartTypes', postgres_handle)
add_user_to_network(twitter_user)
for following in twitter_user.following:
add_user_to_network(following)
for following_following in following.following[:distance]:
add_user_to_network(following_following)
return network