Created
May 14, 2015 20:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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