Skip to content

Instantly share code, notes, and snippets.

@glortho
Created May 14, 2015 20:27
Show Gist options
  • Save glortho/5b4eb808161a8087e730 to your computer and use it in GitHub Desktop.
Save glortho/5b4eb808161a8087e730 to your computer and use it in GitHub Desktop.
Calculate the average rate at which the user has accrued friends and followers
#!/bin/sh
"exec" "twxec" "-e" "average_accrual_rate" "$0" "$@"
from dateutil import parser
{{docstring "Calculate the average rate at which the user has accrued friends and followers"}}
_source = {{string Message_Type ["Twitter", "GNIP"]}}
def average_accrual_rate(msg):
if _source == "GNIP":
user = msg["actor"]
followers = user["followersCount"]
friends = user["friendsCount"]
time_since_creation = parser.parse(user["postedTime"])
latest_tweet_time = parser.parse(msg["postedTime"])
else:
user = msg["user"]
followers = user["followers_count"]
friends = user["friends_count"]
time_since_creation = parser.parse(user["created_at"])
latest_tweet_time = parser.parse(msg["created_at"])
elapsed_days = ((latest_tweet_time - time_since_creation).days + 1.0)
msg["followers_per_day"] = followers / elapsed_days
msg["friends_per_day"] = friends / elapsed_days
return msg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment