Web- Add list of all downloads feature to web service.

This commit is contained in:
Jim Miller 2012-04-19 12:18:40 -05:00
parent 7f7a1a983c
commit 0c85cf1d10
6 changed files with 170 additions and 11 deletions

78
allrecent.html Normal file
View file

@ -0,0 +1,78 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<link href="/css/index.css" rel="stylesheet" type="text/css">
<title>FanFictionDownLoader (fanfiction.net, fanficauthors, fictionalley, ficwad to epub and HTML)</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12136939-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div id='main'>
<h1>
<a href="/" style="text-decoration: none; color: black;">FanFictionDownLoader</a>
</h1>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0320924304307555";
/* Standard */
google_ad_slot = "8974025478";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<!-- <div id='yourfile'> -->
{{yourfile}}
<!-- </div> -->
<div id='helpbox'>
{% for fic in fics %}
<p>
<a href="{{ fic.url }}" title="Link to original story"><span class="recent"><i>{{ fic.title }}</i></span></a>
by <a href="{{ fic.authorUrl }}">{{ fic.author }}</a> <b>Download Count:</b> {{ fic.count }} <br />
<b>Word Count:</b> {{ fic.numWords }} <b>Chapter Count:</b> {{ fic.numChapters }}<br />
{% if fic.category %} <b>Categories:</b> {{ fic.category }} <br /> {% endif %}
{% if fic.genre %} <b>Genres:</b> {{ fic.genre }} <br /> {% endif %}
{% if fic.language %} <b>Language:</b> {{ fic.language }} <br /> {% endif %}
{% if fic.series %} <b>Series:</b> {{ fic.series }} <br /> {% endif %}
{% if fic.characters %} <b>Characters:</b> {{ fic.characters }} <br /> {% endif %}
{% if fic.status %} <b>Status:</b> {{ fic.status }} <br /> {% endif %}
{% if fic.datePublished %} <b>Published:</b> {{ fic.datePublished }} <br /> {% endif %}
{% if fic.dateUpdated %} <b>Last Updated:</b> {{ fic.dateUpdated }} <br /> {% endif %}
{% if fic.dateCreated %} <b>Last Downloaded:</b> {{ fic.dateCreated }} <br /> {% endif %}
{% if fic.rating %} <b>Rating:</b> {{ fic.rating }} <br /> {% endif %}
{% if fic.warnings %} <b>Warnings:</b> {{ fic.warnings }} <br /> {% endif %}
{% if fic.description %} <b>Summary:</b> {{ fic.description }} <br /> {% endif %}
</p>
{% endfor %}
</div>
<script type="text/javascript"><!--
google_ad_client = "ca-pub-0320924304307555";
/* Standard */
google_ad_slot = "8974025478";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</body>
</html>

View file

@ -1,6 +1,6 @@
# ffd-retief-hrd fanfictiondownloader
application: fanfictiondownloader
version: 4-4-5
version: 4-4-7
runtime: python27
api_version: 1
threadsafe: true
@ -35,8 +35,8 @@ handlers:
- url: /.*
script: main.app
builtins:
- datastore_admin: on
#builtins:
#- datastore_admin: on
libraries:
- name: django

View file

@ -218,7 +218,7 @@ class Story:
value = re.sub(p,v,value)
return value
def getMetadata(self, key, removeallentities=False):
def getMetadata(self, key, removeallentities=False, doreplacements=True):
value = None
if self.getLists().has_key(key):
value = ', '.join(self.getList(key))
@ -232,21 +232,22 @@ class Story:
if key == "datePublished" or key == "dateUpdated":
value = value.strftime("%Y-%m-%d")
value=self.doReplacments(value)
if doreplacements:
value=self.doReplacments(value)
if removeallentities and value != None:
return removeAllEntities(value)
else:
return value
def getAllMetadata(self, removeallentities=False):
def getAllMetadata(self, removeallentities=False, doreplacements=True):
'''
All single value *and* list value metadata as strings.
'''
allmetadata = {}
for k in self.metadata.keys():
allmetadata[k] = self.getMetadata(k, removeallentities)
allmetadata[k] = self.getMetadata(k, removeallentities, doreplacements)
for l in self.listables.keys():
allmetadata[l] = self.getMetadata(l, removeallentities)
allmetadata[l] = self.getMetadata(l, removeallentities, doreplacements)
return allmetadata

View file

@ -13,8 +13,23 @@
# limitations under the License.
#
import pickle, copy
from google.appengine.ext import db
class ObjectProperty(db.Property):
data_type = db.Blob
def get_value_for_datastore(self, model_instance):
value = self.__get__(model_instance, model_instance.__class__)
pickled_val = pickle.dumps(value,protocol=pickle.HIGHEST_PROTOCOL)
if value is not None: return db.Blob(pickled_val)
def make_value_from_datastore(self, value):
if value is not None: return pickle.loads(value)
def default_value(self):
return copy.copy(self.default)
class DownloadMeta(db.Model):
user = db.UserProperty()
url = db.StringProperty()
@ -37,3 +52,12 @@ class DownloadData(db.Model):
class UserConfig(db.Model):
user = db.UserProperty()
config = db.BlobProperty()
class SavedMeta(db.Model):
url = db.StringProperty()
title = db.StringProperty()
author = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
count = db.IntegerProperty()
meta = ObjectProperty()

View file

@ -54,9 +54,11 @@
much easier. </p>
</div>
<!-- put announcements here, h3 is a good title size. -->
<h3>New Site Added</h3>
<h3>New Feature Added</h3>
<p>
Support for archive.skyehawke.com has been added. Thanks to Ida Leter for implementing this.
You can now see a list of downloaded fanfics by all
users by <a href="/allrecent">most popular</a>
or <a href="/allrecent?bydate=1">most recent</a>.
</p>
<p>
Questions? Check out our
@ -66,7 +68,7 @@
If you have any problems with this application, please
report them in
the <a href="http://groups.google.com/group/fanfic-downloader">FanFictionDownLoader Google Group</a>. The
<a href="http://4-4-4.fanfictiondownloader.appspot.com">Previous Version</a> is also available for you to use if necessary.
<a href="http://4-4-5.fanfictiondownloader.appspot.com">Previous Version</a> is also available for you to use if necessary.
</p>
<div id='error'>
{{ error_message }}
@ -96,6 +98,9 @@
<p>
Or see your personal list of <a href="/recent">previously downloaded fanfics</a>.
</p>
<p>
See a list of downloaded fanfics by all users by <a href="/allrecent">most popular</a> or <a href="/allrecent?bydate=1">most recent</a>.
</p>
</div>
</form>
{% else %}

51
main.py
View file

@ -303,6 +303,39 @@ class RecentFilesServer(webapp2.RequestHandler):
path = os.path.join(os.path.dirname(__file__), 'recent.html')
self.response.out.write(template.render(path, template_values))
class AllRecentFilesServer(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
return
q = SavedMeta.all()
if self.request.get('bydate'):
q.order('-date')
else:
q.order('-count')
fics = q.fetch(200)
logging.info("Recent fetched %d downloads for user %s."%(len(fics),user.nickname()))
sendslugs = []
for fic in fics:
ficslug = FicSlug(fic)
sendslugs.append(ficslug)
template_values = dict(fics = sendslugs, nickname = user.nickname())
path = os.path.join(os.path.dirname(__file__), 'allrecent.html')
self.response.out.write(template.render(path, template_values))
class FicSlug():
def __init__(self,savedmeta):
self.url = savedmeta.url
self.count = savedmeta.count
for k, v in savedmeta.meta.iteritems():
setattr(self,k,v)
class FanfictionDownloader(UserConfigServer):
def get(self):
self.post()
@ -464,6 +497,8 @@ class FanfictionDownloaderTask(UserConfigServer):
download.url = adapter.getStory().getMetadata('storyUrl')
download.put()
allmeta = adapter.getStory().getAllMetadata(removeallentities=True,doreplacements=False)
outbuffer = StringIO()
writer.writeStory(outbuffer)
data = outbuffer.getvalue()
@ -495,6 +530,21 @@ class FanfictionDownloaderTask(UserConfigServer):
download.completed=True
download.put()
smetal = SavedMeta.all().filter('url =', allmeta['storyUrl'] ).fetch(1)
if smetal and smetal[0]:
smeta = smetal[0]
smeta.count += 1
else:
smeta=SavedMeta()
smeta.count = 1
smeta.url = allmeta['storyUrl']
smeta.title = allmeta['title']
smeta.author = allmeta['author']
smeta.meta = allmeta
smeta.date = datetime.datetime.now()
smeta.put()
logging.info("Download finished OK")
del data
@ -563,6 +613,7 @@ app = webapp2.WSGIApplication([('/', MainHandler),
('/fdown', FanfictionDownloader),
(r'/file.*', FileServer),
('/status', FileStatusServer),
('/allrecent', AllRecentFilesServer),
('/recent', RecentFilesServer),
('/editconfig', EditConfigServer),
('/clearrecent', ClearRecentServer),