wepub

Check-in [cfb00a34a5]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Recently read list. Fix a dequoting API call.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:cfb00a34a59370cc2f2caea8e0a5705387933a4951aecfc8ace32c68a2c53e52
User & Date: ajv-899-334-8894@vsta.org 2016-11-21 14:03:16
Context
2016-11-21
18:30
Use the relative version of the URL for recent book references check-in: 2ba102d516 user: ajv-899-334-8894@vsta.org tags: master, trunk
14:03
Recently read list. Fix a dequoting API call. check-in: cfb00a34a5 user: ajv-899-334-8894@vsta.org tags: master, trunk
2016-11-20
15:20
Make dir/file lists ordered check-in: d66eb4ae50 user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to get.py.

4
5
6
7
8
9
10
11
12



13
14
15
16
17
18
19
20
21
22
23




























































24
25
26
27
28
29



30
31
32
33
34
35
36
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#
# Structure of paths in the server:
#  /
#	Main UI.  Top part is playlist, bottom is file/dir browser
#  /media/<prefix>/...
#	For each prefix of files, its contents is served by
#	way of its path under here.
import os, stat, urllib
import epub




# The GET part of our handling
class GET_mixin(object):

    # Configure our WPlayer GET treatment
    def __init__(self):

	# GET handlers
	self.dispatchers.append( ("GET", self.open_path) )
	self.dispatchers.append( ("GET", self.get_state) )





























































    # "/"; main UI
    def send_top(self):
	app = self.server
	webroot = app.approot
        buf = self.build_header("EPUB categories")




        # Provide a list of top-level document categories
        buf += "<ul>\n"
	for f,cfg in webroot.config["files"]:
            buf += ' <li><a href="/%s/">%s</a></li>\n' % (f,f)
        buf += "</ul>\n"

        buf = self.build_tailer(buf)
................................................................................
            return False,None
        doc = self.vals.get("doc")
        if doc is None:
            return False,None

        # Get a filesystem safe name, see if we can get the info
        try:
            doc = urllib.quote_plus(urllib.unquote(doc))
            f = open("var/state/%s/%s.json" % (self.user, doc), "r")
            buf = f.read()
            f.close()
        except:
            return False,None

        return True,self.send_result(buf, "application/json")







|

>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>







 







|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#
# Structure of paths in the server:
#  /
#	Main UI.  Top part is playlist, bottom is file/dir browser
#  /media/<prefix>/...
#	For each prefix of files, its contents is served by
#	way of its path under here.
import os, time, stat, urllib, json
import epub

# How many of their most recent books to offer
NRECENT = 4

# The GET part of our handling
class GET_mixin(object):

    # Configure our WPlayer GET treatment
    def __init__(self):

	# GET handlers
	self.dispatchers.append( ("GET", self.open_path) )
	self.dispatchers.append( ("GET", self.get_state) )

    # Return HTML enumeration of recent documents
    def list_recent(self):
        global NRECENT

        res = ""

        # Sweep var/state/<user> and get most recent files
        newest = []
        for path,dirs,files in os.walk("var/state/%s" % (self.user,)):
            # There shouldn't be subdirs, but just in case...
            del dirs[:]

            # Process saved files w. position state
            for f in files:
                # Path to saved state
                fn = path + '/' + f

                # Get contents and modified time
                fd = open(fn, "r")
                buf = fd.read()
                d = json.loads(buf)
                url = d["url"]
                st = os.fstat(fd.fileno())
                fd.close()
                ftm = st.st_mtime

                # Assemble this entry
                newest.append( (url, ftm) )

        # Just list of URL's, newest first
        newest.sort(key=lambda tup: tup[1])
        newest = newest[-NRECENT:]
        newest.reverse()

        # Add <a> href's to these files
        res += '<table>\n'
        for f,ftm in newest:
            # Make URL a local ref, so it can straddle HTTP/HTTPS
            #  and internal versus extenal port numbering.
            url = '/' + ('/'.join(f.split('/')[3:]))

            # Extract title of book
            parts = f.split('/')
            title = urllib.unquote_plus(parts[-2])
            secnum = int(parts[-1])

            # When they read it
            tm = time.localtime(ftm)
            tms = time.strftime("%m/%d %H:%M", tm)

            # Add table entry
            res += ' <tr>\n'
            res += '  <td>%s</td>\n' % (tms,)
            res += '  <td><a href="%s">%s (%d)</a></td>\n' % \
                (f, title, secnum)
            res += ' </tr>\n'
        res += '</table>\n'

        return res

    # "/"; main UI
    def send_top(self):
	app = self.server
	webroot = app.approot
        buf = self.build_header("EPUB categories")

        # Recent readings
        buf += self.list_recent()

        # Provide a list of top-level document categories
        buf += "<ul>\n"
	for f,cfg in webroot.config["files"]:
            buf += ' <li><a href="/%s/">%s</a></li>\n' % (f,f)
        buf += "</ul>\n"

        buf = self.build_tailer(buf)
................................................................................
            return False,None
        doc = self.vals.get("doc")
        if doc is None:
            return False,None

        # Get a filesystem safe name, see if we can get the info
        try:
            doc = urllib.quote_plus(urllib.unquote_plus(doc))
            f = open("var/state/%s/%s.json" % (self.user, doc), "r")
            buf = f.read()
            f.close()
        except:
            return False,None

        return True,self.send_result(buf, "application/json")