Example #1
0
 def get_submission_string(self, submission, hide=False):
     ret = []
     if submission.link_flair_text is not None:
         flair = "*[%s]*" % submission.link_flair_text
     else:
         flair = ""
     userflair = ""
     if hasattr(submission, 'author_flair_type'):
         if submission.author_flair_type == 'text' and submission.author_flair_text is not None:
             userflair = " [*%s*] " % submission.author_flair_text
         if submission.author_flair_type == 'richtext':
             for i in submission.author_flair_richtext:
                 if 'e' in i and i['e'] == 'text':
                     userflair = " [*%s*] " % i['t'].strip()
     # import time
     # now = time.time()
     # diff = datetime.fromtimestamp(now) - datetime.utcfromtimestamp(now)
     # time = utils.prettydate(int(submission.created_utc) + int(diff.total_seconds()))
     time = utils.prettydate(int(submission.created_utc))
     if submission.is_self:
         ret.append("[%s] **%s** %s - posted by /u/%s%s to /r/%s, %s" % (self.getsubmissionscore(submission), submission.title, flair, submission.author, userflair, submission.subreddit, time))
         ret.append("%s" % submission.selftext)
         ret.append("<%s>" % submission.shortlink[:1995])
     else:
         ret.append("[%s] **%s** - posted by /u/%s%s to /r/%s, %s" % (self.getsubmissionscore(submission), submission.title, submission.author, userflair, submission.subreddit, time))
         ret.append("")
         if submission.over_18:
             ret.append("**post is NSFW; embed hidden**\n<%s>\t\t<%s>" % (submission.url, submission.shortlink))
         else:
             if hide:
                 ret.append("**post embed hidden by request**\n<%s>\t\t<%s>" % (submission.url, submission.shortlink))
             else:
                 ret.append("%s\t\t<%s>"% (submission.url, submission.shortlink))
     return ret
Example #2
0
 def printcomment(self, comment):
     subreddit = comment.subreddit
     author = comment.author
     submission = comment.submission
     title = submission.title
     score = comment.score
     link = "https://reddit.com" + comment.permalink + "?context=10"
     t = utils.prettydate(int(comment.created_utc))
     return "[%s] comment by **/u/%s** on \"**%s**\" in /r/%s, %s:\n```%s```<%s>" % (str(score), author, title, subreddit, t, comment.body, link)
Example #3
0
File: git.py Project: cholin/gix
 def _convert_commit(self, c):
     return {
       'sha' : c.hex,
       'subject' : utils.truncate(utils.commit_subject(c.message), 60),
       'message' : c.message,
       'commit_time' : utils.prettydate(utils.to_date(c.commit_time)),
       'author' : {
           'name' : c.author.name, 'email' : c.author.email
       },
       'committer' : {
           'name' : c.committer.name, 'email' : c.committer.email
       }
     }
Example #4
0
def check_tweet_age(tweetid, api=None):
    if api is None:
        key = _read_twitter_keys()
        api_key = key['api_key']
        secret = key['api_secret']
        token = key['token']
        token_secret = key['token_secret']

        auth = tweepy.OAuthHandler(api_key, secret)
        auth.set_access_token(token, token_secret)
        api = tweepy.API(auth)
    tweet = api.get_status(tweetid)
    print(tweet.created_at)
    return "Tweet posted: %s" % utils.prettydate(tweet.created_at, utc=True)
Example #5
0
def get_current_weatherbit(text):
    url = "https://api.weatherbit.io/v2.0/current"
    key = utils.get_keys("weatherbit")['key']
    lat,lon,loc = get_lat_lon(text)
    url = url + "?key=%s&units=I&lat=%f&lon=%f" % (key, lat, lon)
    resp = utils.get_json(url)
    if len(resp['data']) > 0:
        data = resp['data'][0]
        obstime = data['ob_time']
        obsdatetime = datetime.strptime(obstime, '%Y-%m-%d %H:%M')
        ret = "```python\n" \
              "Location search result: %s\n" \
              "%s in %s, %s, %s:\n" \
              "  Temp: %.1f (Feels like: %.1f)\n" \
              "  Humidity: %d%%\n" \
              "  Observed: %s at station: %s```" % (loc, data['weather']['description'], data['city_name'], data['state_code'], data['country_code'],
                                     data['temp'], data['app_temp'], data['rh'],
                                     utils.prettydate(obsdatetime, utc=True), data['station'])
        return ret
Example #6
0
def get_latest_ig_post(username):
    url = "https://www.instagram.com/" + username
    req = Request(url, headers={'User-Agent': "ubuntu"})
    #req.headers["User-Agent"] = "windows 10 bot"
    s = urlopen(req).read().decode("utf-8")
    srchstr = "window._sharedData = "
    s = s[s.find(srchstr) + len(srchstr):]
    s = s[:s.find("};") + 1]
    s = json.loads(s)
    # print(s)
    #print("%s" % s['entry_data']['ProfilePage'][0]['user']['media']['nodes'][0]['code'])
    post = s['entry_data']['ProfilePage'][0]['graphql']['user'][
        'edge_owner_to_timeline_media']['edges'][0]['node']
    caption = post['edge_media_to_caption']['edges'][0]['node']['text']
    timestamp = utils.prettydate(post['taken_at_timestamp'])
    location = ""
    if 'location' in post and post['location'] is not None:
        location = " *(%s)* " % post['location']['name']
    url = "https://www.instagram.com/p/" + post['shortcode']
    return "%s**%s**: %s (%s)\n\n%s" % (location, username, caption, timestamp,
                                        url)
Example #7
0
def get_latest_tweet(user):
    with open("keys.json", 'r') as f:
        s = f.read()
    keys = json.loads(s)['keys']
    for key in keys:
        if key['name'] == "twitter":
            api_key = key['api_key']
            secret = key['api_secret']
            token = key['token']
            token_secret = key['token_secret']
    if 'accounts' in json.loads(s):
        map = json.loads(s)['accounts']
    else:
        map = dict()
    user = user.lower()
    if user == "list":
        output = ""
        for u in map:
            output = output + "%s - %s\n" % (u, map[u])
        return output[:-1]
    if user in map:
        user = map[user]
    auth = tweepy.OAuthHandler(api_key, secret)
    auth.set_access_token(token, token_secret)
    api = tweepy.API(auth)
    tweet = api.user_timeline(screen_name=user, count=1)[0]
    tid = tweet.id
    t = tweet.created_at
    nowtime = time.time()
    diff = datetime.fromtimestamp(nowtime) - datetime.utcfromtimestamp(nowtime)
    local = t + diff
    local = utils.prettydate(local)
    # local = local.strftime("%Y-%m-%d %I:%M:%S")
    # print(json.dumps(tweet._json))

    prefix = "Tweet posted"
    if "retweeted_status" in tweet._json:
        prefix = "Retweeted"
    return "%s %s: https://twitter.com/%s/status/%s" % (prefix, local, user,
                                                        tid)
Example #8
0
 def authorprettydate(self):
     return prettydate(self.authordate)
Example #9
0
 def committerprettydate(self):
     return prettydate(self.committerdate)
Example #10
0
 def create_time_since(self):
     return utils.prettydate(self.create_time)
Example #11
0
 def post_time_since(self):
     return utils.prettydate(self.post_time)
Example #12
0
 def update_time_since(self):
     return utils.prettydate(self.update_time)
Example #13
0
 def start_time_since(self):
     return utils.prettydate(self.start_time)