예제 #1
0
while True:

    #Get the newest 10 post from the subreddit
    posts = r.get_subreddit(config.subreddit).get_new(limit=10)

    #loop through each submission
    for post in posts:
        print post.title
        productUrl = functions.removeAffiliateLink(post.url)

        if not db_functions.productExists(productUrl, config.db):
            print 'not exist'
            db_functions.addSubreddit(post.subreddit_id, post.subreddit.display_name, config.db)
            db_functions.addRedditUser(post.author.id, post.author.name, config.db)
            db_functions.addRedditPost(post.id, post.title, post.url, post.subreddit_id, post.author.id, post.created_utc, config.db)
            #ADD check if already copied
            if functions.aliexpressLink(post.url):
                r.login(config.login, config.password)
                affUrl = web_functions.generateAffLink(post.url)
                print affUrl

                r.submit(config.destinationSubreddit2, post.title, url=affUrl)
                #db_functions.recordPost(product[0], config.db)
                web_functions.submitUrl(post.title, affUrl)

                db_functions.addProduct(productUrl, post.title, config.db)
                functions.showCountdown(60)
        #sleep for an hour
    functions.showCountdown(60*60)
예제 #2
0
        if not affUrl is None:
            r.submit(config.destinationSubreddit, product[2], url=affUrl)
            db_functions.recordPost(product[0], config.db)
            web_functions.submitUrl(product[2], affUrl)

#Infinite loop
while True:

    #check when the last time a post was made
    lastPostTime = db_functions.getLastPostTime(config.db)

    if not lastPostTime is None:
        d1 = datetime.strptime(lastPostTime[0], "%Y-%m-%d %H:%M:%S.%f")
        d2 = datetime.now()

        # convert to unix timestamp
        d1_ts = time.mktime(d1.timetuple())
        d2_ts = time.mktime(d2.timetuple())

        # they are now in seconds, subtract and then divide by 60 to get minutes.
        timediff = int(d2_ts-d1_ts) / 60

        #If it's been more than 30 minutes since the last post then generate a new one.
        if timediff > 30:
            makePost()
    else:
        makePost()

    #sleep for the configured amount of time
    functions.showCountdown(config.posterDelay)