コード例 #1
0
def scheduled_job():
    subredditArray = ['rit','minecraft','bitcoin',
    'wallstreetbets','robinhood','gamestop',
    'playstation','xbox','nintendo',
    'gaming','lsrs']
    subredditID = 1
    print(subredditArray)
    for subreddit in subredditArray:
        # API endpoint will crash if you go too fast, after some tests, 1 second is the optimal speed. 
        time.sleep(1)
        print(subredditID)
        url = "/r/" + subreddit + "/about/"
        result = (baseAPI.getResult(url))
        submission = baseAPI.getSubmissionResult(subreddit)['metadata']['total_results']
        comment = baseAPI.getCommentResult(subreddit)['metadata']['total_results']
        subscribers = result['data']['subscribers']
        activeSubscribers = result['data']['active_user_count']
        date=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        res = requests.post('https://brick-subreddit.herokuapp.com/info', 
        data={'subreddit_id':subredditID,
        'submission':submission,
        'comment':comment,
        'subscribers':subscribers,
        'active_subscribers':activeSubscribers,
        'date':date})
        print(res)
        if res.status_code == 200:
            print('Success!')
        elif res.status_code == 404:
            print('Not Found.')
        subredditID = subredditID + 1
コード例 #2
0
def scheduled_job():
    subredditArray = baseSQL.returnSelectAllAbbreviation()

    subredditID = 1
    print(subredditArray)

    for subreddit in subredditArray:
        subreddit = numpy.asarray(subreddit)

        subredditID = subreddit[0]
        # API endpoint will crash if you go too fast, after some tests, 2 second is the optimal speed on Heroku.
        time.sleep(2)
        print(subredditID)

        url = "/r/" + subreddit[2] + "/about/"

        result = (baseAPI.getResult(url))
        submission = baseAPI.getSubmissionResult(
            subreddit[2])['metadata']['total_results']
        comment = baseAPI.getCommentResult(
            subreddit[2])['metadata']['total_results']
        subscribers = result['data']['subscribers']
        activeSubscribers = result['data']['active_user_count']
        date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        oldArray = baseSQL.returnUpdateCount(subreddit[0])
        for oldArrayVal in oldArray:
            oldComment = oldArrayVal[0]
            oldSubmission = oldArrayVal[1]
            oldSubscriber = oldArrayVal[2]
            oldActiveSubscriber = oldArrayVal[3]

            commentChange = comment - oldComment
            submissionChange = submission - oldSubmission
            subscriberChange = subscribers - oldSubscriber
            activeSubChange = activeSubscribers - oldActiveSubscriber

            baseSQL.insertCalculation(date, commentChange, submissionChange,
                                      subscriberChange, activeSubChange,
                                      subredditID, comment, submission,
                                      subscribers, activeSubscribers)

        baseSQL.insertRowInformation(subredditID, date, subscribers,
                                     activeSubscribers, submission, comment)

    baseSQL.selectAllInformation()
コード例 #3
0
##############################################
# Author:                                    #
# Edward Riley                               #
##############################################

import baseAPI
import json

resultPopular = (baseAPI.getResult("subreddits/popular/"))

# SAVE THIS FOR FUTURE GUIDANCE ON KEYWORDS - EDWARD RILEY
# for each in resultPopular['data']['children'][0]['data']:
#    print(each)

prettyJSON = json.dumps(resultPopular['data']['children'][0]['data']['title'],
                        indent=2)
counter = 0
array = []
try:
    while True:
        subArray = []
        name = resultPopular['data']['children'][counter]['data']['title']
        subscribers = resultPopular['data']['children'][counter]['data'][
            'subscribers']

        subArray.append(name)
        subArray.append(subscribers)

        array.append(subArray)
        counter = counter + 1
except:
コード例 #4
0
subredditArray = baseSQL.returnSelectAllAbbreviation()

subredditID = 1

for subreddit in subredditArray:

    subreddit = numpy.asarray(subreddit)

    subredditID = subreddit[0]
    # API endpoint will crash if you go too fast, after some tests, 1 second is the optimal speed.
    time.sleep(1)
    print(subredditID)

    url = "/r/" + subreddit[2] + "/about/"

    result = (baseAPI.getResult(url))
    submission = baseAPI.getSubmissionResult(
        subreddit[2])['metadata']['total_results']
    comment = baseAPI.getCommentResult(
        subreddit[2])['metadata']['total_results']
    subscribers = result['data']['subscribers']
    activeSubscribers = result['data']['active_user_count']
    date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

    oldArray = baseSQL.returnUpdateCount(subreddit[0])
    for oldArrayVal in oldArray:
        oldComment = oldArrayVal[0]
        oldSubmission = oldArrayVal[1]
        oldSubscriber = oldArrayVal[2]
        oldActiveSubscriber = oldArrayVal[3]