예제 #1
0
def get_replies(reply_id):
    import json
    from pattern.web import URL, Twitter

    reply_id = reply_id - 1
    url = URL("https://api.twitter.com/1.1/statuses/mentions_timeline.json",
              method="get",
              query={"since_id": reply_id})

    twitter = Twitter(license=ccpattern)
    url = twitter._authenticate(url)

    user_replies = {}
    bot_replies = {}
    try:
        data = json.loads(url.open().read())
        for reply in data:
            name = reply["user"]["name"].encode('utf-8').strip()
            text = reply["text"].replace("@BotsVsQuotes", "").strip()
            if name == "BotsVsQuotes":
                #bot quotes
                text = text.split(":")
                char_name = text[0]
                bot_replies[char_name] = "".join(text[1:]).strip()
            else:
                #user quotes
                user_replies[name] = text
    except Exception as e:
        print e
        print e.src
        print e.src.read()
        return {}, {}
    return bot_replies, user_replies
예제 #2
0
def reply_tweet(tweet, reply_id, reply_user="******"):
    from pattern.web import URL, Twitter

    tweet = reply_user + " " + tweet
    url = URL("https://api.twitter.com/1.1/statuses/update.json",
              method="post",
              query={
                  "status": tweet,
                  "in_reply_to_status_id": reply_id
              })

    twitter = Twitter(license=ccpattern)
    url = twitter._authenticate(url)

    try:
        # Send the post request.
        url.open()
    except Exception as e:
        print e
        print e.src
        print e.src.read()
예제 #3
0
def post_tweet(tweet):
    from pattern.web import URL, Twitter
    import json

    url = URL("https://api.twitter.com/1.1/statuses/update.json",
              method="post",
              query={"status": tweet})

    twitter = Twitter(license=ccpattern)
    url = twitter._authenticate(url)

    try:
        # Send the post request.
        data = url.open().read()
    except Exception as e:
        print e
        print e.src
        print e.src.read()
        return None

    data = json.loads(data)
    return int(data[u'id'])
예제 #4
0
from pattern.web import URL, Twitter

# Tweet to post:
tweet = "avalancheddar"

# The API for posting is described here:
# # https://dev.twitter.com/rest/reference/post/statuses/update
url = URL("https://api.twitter.com/1.1/statuses/update.json",
          method="post",
          query={"status": tweet})

# We'll use the Twitter._authenticate() method to authenticate ourselves
# as @ccpattern (so the new tweet will appear on @ccpattern's page):
twitter = Twitter(license=ccpattern)
url = twitter._authenticate(url)

try:
    # Send the post request.
    url.open()
except Exception as e:
    print e
    print e.src
    print e.src.read()

# To create your own Twitter bot:

# 1) You need a new e-mail address for the bot (e.g., gmail.com).
# 2) You need a new Twitter account.
# 3) Verify the Twitter account from the e-mail they send you.
# 4) Verify the Twitter account with a mobile phone number (this is mandatory):
예제 #5
0
# Tip: we could create a bot that follows everyone,
# hope they follow us back, and then invent tweets that address them.

from pattern.web import URL, Twitter

# Tweet to post:
tweet = "avalancheddar"

# The API for posting is described here:
# # https://dev.twitter.com/rest/reference/post/statuses/update
url = URL("https://api.twitter.com/1.1/statuses/update.json", method="post", query={"status": tweet})

# We'll use the Twitter._authenticate() method to authenticate ourselves 
# as @ccpattern (so the new tweet will appear on @ccpattern's page):
twitter = Twitter(license=ccpattern)
url = twitter._authenticate(url)

try:
    # Send the post request.
    url.open()
except Exception as e:
    print e
    print e.src
    print e.src.read()
    
# To create your own Twitter bot:

# 1) You need a new e-mail address for the bot (e.g., gmail.com).
# 2) You need a new Twitter account.
# 3) Verify the Twitter account from the e-mail they send you.
# 4) Verify the Twitter account with a mobile phone number (this is mandatory):