Make URL shortening generic in tweets.py
This commit is contained in:
parent
931c941f42
commit
23fbc2cb95
1 changed files with 6 additions and 6 deletions
|
@ -15,7 +15,7 @@ class Module(object):
|
||||||
|
|
||||||
def __init__(self, bot, events, exports):
|
def __init__(self, bot, events, exports):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.bitly_is_enabled = "bitly" in self.bot.modules.modules
|
self.url_shortener_enabled = "bitly" in self.bot.modules.modules
|
||||||
self.events = events
|
self.events = events
|
||||||
|
|
||||||
events.on("received").on("command").on("tweet", "tw"
|
events.on("received").on("command").on("tweet", "tw"
|
||||||
|
@ -67,13 +67,13 @@ class Module(object):
|
||||||
linked_id = tweet["id"]
|
linked_id = tweet["id"]
|
||||||
username = "@%s" % tweet["user"]["screen_name"]
|
username = "@%s" % tweet["user"]["screen_name"]
|
||||||
|
|
||||||
bitly_link = ""
|
url_shortener_link = ""
|
||||||
if self.bitly_is_enabled:
|
if self.url_shortener_enabled:
|
||||||
chopped_uname = username[1:]
|
chopped_uname = username[1:]
|
||||||
tweet_link = "https://twitter.com/%s/status/%s" % (
|
tweet_link = "https://twitter.com/%s/status/%s" % (
|
||||||
chopped_uname, linked_id)
|
chopped_uname, linked_id)
|
||||||
|
|
||||||
bitly_link = " -- " + self.events.on("get").on(
|
url_shortener_link = " -- " + self.events.on("get").on(
|
||||||
"shortlink").call(
|
"shortlink").call(
|
||||||
url=tweet_link)[0]
|
url=tweet_link)[0]
|
||||||
|
|
||||||
|
@ -91,14 +91,14 @@ class Module(object):
|
||||||
username, retweet_timestamp,
|
username, retweet_timestamp,
|
||||||
original_username, original_timestamp,
|
original_username, original_timestamp,
|
||||||
original_text,
|
original_text,
|
||||||
bitly_link))
|
url_shortener_link))
|
||||||
else:
|
else:
|
||||||
event["stdout"].write("(%s, %s) %s %s" % (username,
|
event["stdout"].write("(%s, %s) %s %s" % (username,
|
||||||
self.make_timestamp(
|
self.make_timestamp(
|
||||||
tweet[
|
tweet[
|
||||||
"created_at"]),
|
"created_at"]),
|
||||||
tweet["text"],
|
tweet["text"],
|
||||||
bitly_link)
|
url_shortener_link)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
event["stderr"].write("Invalid tweet identifiers provided")
|
event["stderr"].write("Invalid tweet identifiers provided")
|
||||||
|
|
Loading…
Reference in a new issue