favicons (disabled)
parent
b3dca7598d
commit
7911e3f117
17
app.py
17
app.py
|
|
@ -1,5 +1,6 @@
|
|||
from flask import Flask, Response, abort
|
||||
from flask import Flask, Response, abort, request
|
||||
from parsers.nvidia import NvidiaParser
|
||||
from urllib.parse import urlparse
|
||||
import os, time, threading
|
||||
|
||||
class ParserData:
|
||||
|
|
@ -82,6 +83,19 @@ indexPage += '</html>'
|
|||
def index():
|
||||
return indexPage
|
||||
|
||||
#@app.route('/favicon.ico')
|
||||
#def favicon():
|
||||
# referrer = request.referrer
|
||||
# if referrer != None:
|
||||
# u = urlparse(referrer)
|
||||
#
|
||||
# for parser in parsers:
|
||||
# if parser.parser.URL == u.path:
|
||||
# favi = parser.parser.favicon
|
||||
# return Response(favi.content, mimetype=favi.headers['Content-Type'])
|
||||
#
|
||||
# abort(404)
|
||||
|
||||
runParserWorkers()
|
||||
|
||||
for parser in parsers:
|
||||
|
|
@ -91,4 +105,3 @@ for parser in parsers:
|
|||
if parser.rss == None:
|
||||
abort(404)
|
||||
return Response(parser.rss, mimetype='text/xml')
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from feedgen.feed import FeedGenerator
|
|||
from collections import namedtuple
|
||||
import multiprocessing
|
||||
from datetime import datetime
|
||||
import requests
|
||||
|
||||
Entry = namedtuple('Entry', 'url fe')
|
||||
|
||||
|
|
@ -10,6 +11,18 @@ class NvidiaParser:
|
|||
NAME = 'NVidia Research'
|
||||
URL = '/nvidia'
|
||||
CACHE_TIMEOUT = 3600
|
||||
root_url = 'https://research.nvidia.com'
|
||||
favicon = None
|
||||
|
||||
def loadFavicon(self):
|
||||
try:
|
||||
favUrl = NvidiaParser.root_url + '/themes/custom/nvidia/favicon.ico'
|
||||
self.favicon = requests.get(favUrl)
|
||||
except:
|
||||
pass
|
||||
|
||||
# def __init__(self):
|
||||
# self.loadFavicon()
|
||||
|
||||
def parseNvidiaDate(entry):
|
||||
dom = pq(entry.url)
|
||||
|
|
@ -20,22 +33,20 @@ class NvidiaParser:
|
|||
entry.fe.pubDate(time)
|
||||
|
||||
def getRss(self):
|
||||
root_url = 'https://research.nvidia.com'
|
||||
d = pq(root_url +'/publications')
|
||||
d = pq(self.root_url +'/publications')
|
||||
# self.loadFavicon()
|
||||
|
||||
fg = FeedGenerator()
|
||||
fg.id(root_url)
|
||||
fg.id(self.root_url)
|
||||
fg.title('NVidia Research')
|
||||
fg.link(href=root_url, rel='alternate')
|
||||
fg.logo(root_url + '/themes/custom/nvidia/favicon.ico')
|
||||
fg.link(href=self.root_url, rel='alternate')
|
||||
fg.description('NVidia Research papers')
|
||||
|
||||
entries = []
|
||||
print('RSS GOT')
|
||||
|
||||
for elem in d('.views-field-title').items():
|
||||
link = elem.find('a')
|
||||
url = root_url + link.attr.href
|
||||
url = self.root_url + link.attr.href
|
||||
title = link.text()
|
||||
|
||||
fe = fg.add_entry()
|
||||
|
|
@ -45,8 +56,12 @@ class NvidiaParser:
|
|||
|
||||
entries.append(Entry(url, fe))
|
||||
|
||||
with multiprocessing.Pool(8) as p:
|
||||
p.map(NvidiaParser.parseNvidiaDate, entries)
|
||||
for entry in entries:
|
||||
NvidiaParser.parseNvidiaDate(entry)
|
||||
print(entry.url)
|
||||
|
||||
# with multiprocessing.Pool(8) as p:
|
||||
# p.map(NvidiaParser.parseNvidiaDate, entries)
|
||||
|
||||
return fg.rss_str()
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue