Esempio n. 1
0
def create_website_entry():
    data = request.json
    new_website = Website(name=data['website'],
                          url=data['url'],
                          website=data['website_information'])
    new_website.save()
    return Response("Entry in.", 200)
Esempio n. 2
0
def update_headlines():
    data = request.json
    name = data['website']
    website_info = {
        'website': name,
        'main_headline': data['main_headline'],
        'minor_headlines': data['minor_headlines']
    }
    Website.objects(name=name).update(
        set__website=website_info,
        set__last_update=datetime.datetime.now().strftime(
            "%m/%d/%Y, %H:%M:%S"))
    return website_info
def write_facts(update: Updater, url):
    web = Website(url)
    s = Website.get_data(web)
    if s is not None:
        ma = 0
        al = s['all']
        data = ''
        for i in range(len(al)):
            if al[i]['upvotes'] > ma and al[i]['type'] == 'cat':
                ma = al[i]['upvotes']
                data = ''
                data += f'User: {al[i]["user"]["name"]["first"]} {al[i]["user"]["name"]["last"]}\n' \
                    f'{al[i]["text"]}\nLikes: {al[i]["upvotes"]}'
        return data
    else:
        return ''
 def test_bad_request(self):
     with patch('classes.requests.get') as mock_get:
         mock_get.return_value.status_code = 0
         facts = Website('http://google.com').get_data()
     self.assertEqual(facts, None)
 def test_ok_request(self):
     with patch('classes.requests.get') as mock_get:
         mock_get.return_value.status_code = 200
         mock_get.return_value.json.return_value = 'hello'
         data = Website('http://google.com').get_data()
     self.assertEqual(data, 'hello')
Esempio n. 6
0
def get_headlines(website_name):
    # every website has only one entry in DB
    website = list(Website.objects(name=website_name))[0]
    return website.website
Esempio n. 7
0
def website_names():
    websites = list(Website.objects(__raw__={}))
    return [website.name for website in websites]
Esempio n. 8
0
def get_last_update_time(website_name):
    # every website has only one entry in DB
    website = list(Website.objects(name=website_name))[0]
    return website.last_update
Esempio n. 9
0
BUDS_TO_GO = Website(
    name = "buds2go",
    domain = "https://www.buds2go.ca",
    pages = [
        Page(
            url="https://www.buds2go.ca/product-category/flowers"
        )
    ],
    request = {
        "method": "POST",
        "data": {
            "alg_products_per_page": -1
        }
    },
    attributes = {
        "name": {
            "path": lambda soup : soup.findAll("", { "class": "product-title" }),
            "selector": lambda dom : dom.text,
        },
        "price": {
            "path": lambda soup : [dom.find("", {"class": "amount"}) for dom in soup.findAll("", { "class": "price-wrapper" })],
            "selector": lambda dom : dom.text,
        },
        "url": {
            "path": lambda soup : [dom.find("a") for dom in soup.findAll("", { "class": "product-title" })],
            "selector": lambda dom : dom["href"],
        },
    },
    # get_detail = {
    #     "available": {
    #         "path": lambda soup : [soup.find("", {"class": "availability"})],
    #         "selector": lambda dom : dom.text,
    #     },
    # }
)