Exemple #1
0
class TestGetLast(unittest.TestCase):

    def setUp(self):
        self.hn = HackerNews()

    def test_get_item(self):
        items = self.hn.get_last(5)
        self.assertIsInstance(items, list)
        self.assertEqual(len(items), 5)
        self.assertIsInstance(items[0], Item)

    def tearDown(self):
        self.hn.session.close()
Exemple #2
0
"""Saltiest Hacker with Flask."""
from flask import Flask
import requests
from hackernews import HackerNews
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
import pandas as pd
import os
from dotenv import load_dotenv
import psycopg2
from psycopg2.extras import execute_values

hn = HackerNews()

# request last 2000 items
last = hn.get_last(2000)

# view item type and item text
items_dict = []
for item in last:
    #only keep users and text from comments
    if item.item_type == 'comment':
        user = item.by
        text = item.text

        #output metrics as a row
        dictionary_data = {"User": user, "Text": text}
        items_dict.append(dictionary_data)

# create dataframe for modelling use
df = pd.DataFrame.from_dict(items_dict)