Beispiel #1
0
def getPH(num=5):
    phc = ProductHuntClient(os.environ['PHC'], os.environ['PHS'],
                            "http://localhost:5000")
    # Example request
    ph = []
    for s in phc.get_todays_posts()[:int(num)]:
        story = {}
        story["uid"] = s.id
        story["updateDate"] = getTime().strftime('%Y-%m-%dT%H:%M:%S.0Z')
        story["titleText"] = "From PH: " + (s.name).encode('utf-8') + ", " + (
            s.tagline).encode('utf-8')

        story["title"] = (s.name).encode('utf-8') + ", " + (
            s.tagline).encode('utf-8')
        story["commentURL"] = s.discussion_url.encode('utf-8')
        story["thumbnail"] = "http://i.imgur.com/BOUdyc2.jpg"

        if s.comments_count:
            story["mainText"] = "With " + str(
                s.votes_count) + " up votes and " + comments(
                    s.comments_count) + (s.name).encode('utf-8') + ", " + (
                        s.tagline).encode('utf-8')
        else:
            story["mainText"] = "With " + str(
                s.votes_count) + " up votes: " + (s.name).encode(
                    'utf-8') + ", " + (s.tagline).encode('utf-8')

        story["redirectionUrl"] = s.redirect_url
        ph.append(story)

    return ph
Beispiel #2
0
def run(key, secret, uri, token):
    phc = ProductHuntClient(key, secret, uri, token)
    # Example request
    try:
        with io.open('popular_YYYY-mm-dd.csv',
                     'w',
                     newline='',
                     encoding="utf-8") as csvfile:
            spamwriter = csv.writer(csvfile,
                                    delimiter=';',
                                    quotechar='|',
                                    quoting=csv.QUOTE_ALL)
            for post in phc.get_todays_posts():
                name = post.name
                tagline = post.tagline
                urlLogo = post.screenshot_url
                urlProduct = post.redirect_url
                votes = post.votes_count
                coments = post.comments_count
                hunter = post.user.name
                hunterlink = post.user.profile_url
                coment = post.comments
                print('name: ', name)
                print('tagline :', tagline)
                print('hunter :', hunter)
                print('hunterlink :', hunterlink)
                spamwriter.writerow(
                    [name, tagline, urlLogo, urlProduct, votes, coments])

            print(post.current_user)

    except ProductHuntError as e:
        print(e.error_message)
        print(e.status_code)
Beispiel #3
0
def run(key, secret, uri, token):
    phc = ProductHuntClient(key, secret, uri, token)

    # Example request
    try:
        for post in phc.get_todays_posts():
            print(post.name)
    except ProductHuntError as e:
        print(e.error_message)
        print(e.status_code)
Beispiel #4
0
def run(key, secret, uri, token):
    phc = ProductHuntClient(key, secret, uri, token)

    # Example request
    try:
        with open('output.csv', 'w', newline='', encoding='utf-8') as csvfile:
            fieldnames = ['Name', 'Tagline', 'logo URL', 'product URL', 'Upvotes', 'Comments']
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames, delimiter=";", quoting=csv.QUOTE_ALL)
            writer.writeheader()
            for post in phc.get_todays_posts():
                line = {'Name': post.name, 'Tagline': post.tagline, 'logo URL': post.screenshot_url, 'product URL': post.redirect_url,
                        'Upvotes': post.votes_count, 'Comments': post.comments_count}
                writer.writerow(line)

    except ProductHuntError as e:
        print(e.error_message)
        print(e.status_code)
Beispiel #5
0
def setup_ph_client(config_file):
    with open(os.path.join(os.getcwd(), config_file), 'r') as config:
        cfg = yaml.load(config)
        key = cfg['api']['key']
        secret = cfg['api']['secret']
        uri = cfg['api']['redirect_uri']
        token = cfg['api']['dev_token']

    return ProductHuntClient(key, secret, uri, token)
Beispiel #6
0
def run(key, secret, uri, token):
    phc = ProductHuntClient(key, secret, uri, token)

    # Example request
    try:
        with open('popular_2018-04-20.csv', 'w', newline='',
                  encoding='UTF8') as csvfile:
            spamwriter = csv.writer(csvfile,
                                    delimiter=';',
                                    quoting=csv.QUOTE_ALL)
            spamwriter.writerow([
                'Name', 'TagLine', 'Logo', 'URL', 'NumberOfUpvotes',
                'NumberOfComments', 'HunterName'
            ])

            for post in phc.get_todays_posts():
                print('Name: ', post.name)
                print('Tagline: ', post.tagline)

                logo = post.screenshot_url['850px']
                print('Logo: ', logo)
                print('URL: ', post.redirect_url)
                print('number of upvotes: ', post.votes_count)
                print('number of comments: ', post.comments_count)
                print('Hunter name: ', post.user.name)

                spamwriter.writerow([
                    post.name, post.tagline, logo, post.redirect_url,
                    post.votes_count, post.comments_count, post.user.name
                ])

                print('-------------------------------------------')
                print('-------------------------------------------')

    except ProductHuntError as e:
        print(e.error_message)
        print(e.status_code)
from ph_py import ProductHuntClient

client_id = '<YOUR_APP_ID>'
client_secret = '<YOUR_APP_SECRET>'
redirect_uri = 'http://localhost:5000'
file_name = 'posts.csv'

daysBack = 600 #download posts for the last daysBack days

phc = ProductHuntClient(client_id, client_secret, redirect_uri)

with open(file_name, "a") as myfile:
    myfile.write('post_id,post_data,post_name,post_tagline,post_comments,post_votes,post_url,user_id,user_name,user_nickname')
    myfile.write('\n')
    for day in range(1,daysBack):
        print str(day)+" - ",
        for post in phc.get_previous_days_posts(day):
            print str(post.id),
            myfile.write(str(post.id))
            myfile.write(','+post.created_at)
            myfile.write(',\"'+post.name.encode('ascii', 'ignore').decode('ascii').replace('"','_')+'\"')
            myfile.write(',\"'+post.tagline.encode('ascii', 'ignore').decode('ascii').replace('"','_')+'\"')
            myfile.write(','+str(post.comments_count))
            myfile.write(','+str(post.votes_count))
            myfile.write(','+post.redirect_url)
            myfile.write(','+str(post.user.id))
            myfile.write(',\"'+post.user.name.encode('ascii', 'ignore').decode('ascii')+'\"')
            myfile.write(',\"'+post.user.username.encode('ascii', 'ignore').decode('ascii')+'\"')
            myfile.write('\n')
        print
myfile.close()