Esempio n. 1
0
def makePost():
    product = db_functions.getProductToPost(config.db)
    if not product is None:
        print product[1]
        r.login(config.login, config.password)
        affUrl = web_functions.generateAffLink(product[1])
        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)
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)