Пример #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
import praw
import time

from config import config
from functions import db_functions
from functions import functions
from datetime import datetime

r = praw.Reddit(user_agent=config.userAgentString)
while True:

    #Get the top n reddit post from the subreddit
    posts = r.get_subreddit(config.subreddit).get_new(limit=1000)

    #loop through each submission
    for post in posts:
        try:
            productUrl = functions.removeAffiliateLink(post.url)
            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)
            #check if this is an aliexpress link
            if functions.aliexpressLink(productUrl):
                print productUrl
                db_functions.addProduct(productUrl, post.title, config.db)
        except:
            pass

    #sleep for an hour
    functions.showCountdown(60*60)