当前位置: 首页>>代码示例>>Python>>正文


Python Twitter.query方法代码示例

本文整理汇总了Python中twitter.Twitter.query方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.query方法的具体用法?Python Twitter.query怎么用?Python Twitter.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twitter.Twitter的用法示例。


在下文中一共展示了Twitter.query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import query [as 别名]
def main():
    conf = get_conf()
    twitter = Twitter(conf)

    parser = argparse.ArgumentParser()

    parser.add_argument('-q', '--query', type = str,
        help = "Gets all tweets and retweets for a specifc search query (realtime)")
    parser.add_argument('-t', '--timeline', action = "store_true",
        help = "Gets all tweets for the authenticated user")
    parser.add_argument('-u', '--user', type = str,
        help = "Get a timeline with a username")
    parser.add_argument('-s', '--search', type = str,
        help = "Get results for a search query (not realtime)")
    parser.add_argument('-l', '--lookup',
        help = "Get all the details for a single tweet")
    parser.add_argument('-rts', '--retweetstats',
        help = "Returns user info of up to 100 people that retweeted the tweet specified")

    args = parser.parse_args()

    if args.query:
        twitter.query(args.query)
    elif args.timeline:
        twitter.run_timeline()
    elif args.user:
        twitter.user_timeline()
    elif args.search:
        twitter.search(args.search)
    elif args.lookup:
        twitter.lookup(args.lookup)
    elif args.retweetstats:
        sid = args.retweetstats
        print("Collecting retweeters for %s" % sid)
        users = twitter.retweetstats(sid)
        path = "%s-retweeters.json" % sid

        with open(path, "w") as f:
            f.write(json.dumps(users))

        print("Written retweeters to %s" % path)
    else:
        parser.print_help()
开发者ID:hay,项目名称:twitter-cli,代码行数:45,代码来源:twitter-cli.py

示例2: get

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import query [as 别名]
  def get(self):
    sources = {source.key.id(): source for source in Twitter.query()}
    if not sources:
      return

    # just auth as me or the first user. TODO: use app-only auth instead.
    auther = sources.get('schnarfed') or sources.values()[0]
    usernames = sources.keys()
    users = []
    for i in range(0, len(usernames), TWITTER_USERS_PER_LOOKUP):
      url = TWITTER_API_USER_LOOKUP % ','.join(
        usernames[i:i + TWITTER_USERS_PER_LOOKUP])
      users += auther.gr_source.urlopen(url)

    for user in users:
      source = sources[user['screen_name']]
      new_actor = auther.gr_source.user_to_actor(user)
      maybe_update_picture(source, new_actor, self)
开发者ID:uniteddiversity,项目名称:bridgy,代码行数:20,代码来源:cron.py

示例3: get

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import query [as 别名]
  def get(self):
    sources = {source.key.id(): source for source in Twitter.query()}
    if not sources:
      return

    # just auth as me or the first user. TODO: use app-only auth instead.
    auther = sources.get('schnarfed') or sources.values()[0]
    usernames = sources.keys()
    users = []
    for i in range(0, len(usernames), TWITTER_USERS_PER_LOOKUP):
      username_batch = usernames[i:i + TWITTER_USERS_PER_LOOKUP]
      url = TWITTER_API_USER_LOOKUP % ','.join(username_batch)
      try:
        users += auther.gr_source.urlopen(url)
      except Exception, e:
        code, body = util.interpret_http_exception(e)
        if not (code == '404' and len(username_batch) == 1):
          # 404 for a single user means they deleted their account. otherwise...
          raise
开发者ID:mblaney,项目名称:bridgy,代码行数:21,代码来源:cron.py

示例4: update_streams_once

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import query [as 别名]
def update_streams_once():
  """Connects new Twitter accounts and disconnects disabled and deleted ones.

  Separated from update_streams() mainly for testing.
  """
  global streams

  # Delete closed streams. They'll be reconnected below.
  for key, stream in streams.items():
    if not stream.running:
      del streams[key]

  query = Twitter.query(Twitter.status != 'disabled')
  sources = {t.key: t for t in query.iter()}
  stream_keys = set(streams.keys())
  source_keys = set(sources.keys())

  # Connect to new accounts
  to_connect = source_keys - stream_keys
  if to_connect:
    logging.info('Connecting %d streams', len(to_connect))
  for key in to_connect:
    source = sources[key]
    auth = twitter_auth.tweepy_auth(*source.auth_entity.get().access_token())
    streams[key] = streaming.Stream(auth, Listener(source), secure=True)
    # run stream in *non*-background thread, since app engine backends have a
    # fixed limit of 10 background threads per instance. normal threads are only
    # limited by memory, and since we're starting them from a background thread,
    # they're not bound to an HTTP request.
    # http://stackoverflow.com/a/20896720/186123
    streams[key].userstream(async=True)

  # Disconnect from deleted or disabled accounts
  to_disconnect = stream_keys - source_keys
  if to_disconnect:
    logging.info('Disconnecting %d streams', len(to_disconnect))
  for key in to_disconnect:
    streams[key].disconnect()
    del streams[key]
开发者ID:sanduhrs,项目名称:bridgy,代码行数:41,代码来源:twitter_streaming.py

示例5: get

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import query [as 别名]
  def get(self):
    sources = {source.key.id(): source for source in Twitter.query()}
    if not sources:
      return

    # just auth as me or the first user. TODO: use app-ony auth instead.
    auther = sources.get('schnarfed') or sources.values()[0]
    usernames = sources.keys()
    users = []
    for i in range(0, len(usernames), USERS_PER_LOOKUP):
      url = TWITTER_API_USER_LOOKUP % ','.join(usernames[i:i + USERS_PER_LOOKUP])
      users += json.loads(auther.as_source.urlopen(url).read())

    for user in users:
      source = sources[user['screen_name']]
      new_actor = auther.as_source.user_to_actor(user)
      new_pic = new_actor.get('image', {}).get('url')
      if source.picture != new_pic:
        logging.info('Updating profile picture for %s from %s to %s',
                     source.bridgy_url(self), source.picture, new_pic)
        util.CachedPage.invalidate('/users')
        source.picture = new_pic
        source.put()
开发者ID:sanduhrs,项目名称:bridgy,代码行数:25,代码来源:cron.py


注:本文中的twitter.Twitter.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。