Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
decentral1se
etherdump
Commits
2e112d38
Commit
2e112d38
authored
Jan 12, 2018
by
Michael Murtaugh
Browse files
index command changes for python3
parent
ba6035c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
2e112d38
...
...
@@ -9,7 +9,7 @@ Requirements
*
python3
*
html5lib
*
requests (settext)
*
python-datutil, jinja2 (index subcommand)
*
python-dat
e
util, jinja2 (index subcommand)
Installation
-------------
...
...
etherdump/commands/index.py
View file @
2e112d38
from
__future__
import
print_function
from
argparse
import
ArgumentParser
import
sys
,
json
,
re
,
os
,
urlparse
import
sys
,
json
,
re
,
os
from
datetime
import
datetime
from
urllib
import
urlencode
from
urllib2
import
HTTPError
try
:
# python2
from
urllib2
import
urlopen
,
URLError
,
HTTPError
from
urllib
import
urlencode
from
urlparse
import
urlparse
,
urlunparse
except
ImportError
:
# python3
from
urllib.parse
import
urlparse
,
urlunparse
,
urlencode
,
quote
from
urllib.request
import
urlopen
,
URLError
,
HTTPError
from
jinja2
import
FileSystemLoader
,
Environment
from
common
import
*
from
etherdump.commands.
common
import
*
from
time
import
sleep
import
dateutil.parser
...
...
@@ -44,9 +53,9 @@ def absurl (url, base=None):
return
url
def
url_base
(
url
):
(
scheme
,
netloc
,
path
,
params
,
query
,
fragment
)
=
urlparse
.
urlparse
(
url
)
(
scheme
,
netloc
,
path
,
params
,
query
,
fragment
)
=
urlparse
(
url
)
path
,
_
=
os
.
path
.
split
(
path
.
lstrip
(
"/"
))
ret
=
urlparse
.
urlunparse
((
scheme
,
netloc
,
path
,
None
,
None
,
None
))
ret
=
urlunparse
((
scheme
,
netloc
,
path
,
None
,
None
,
None
))
if
ret
:
ret
+=
"/"
return
ret
...
...
@@ -116,14 +125,14 @@ def main (args):
pads
=
map
(
loadmeta
,
inputs
)
pads
=
map
(
fixdates
,
pads
)
args
.
pads
=
pads
args
.
pads
=
list
(
pads
)
if
args
.
timestamp
==
None
:
args
.
timestamp
=
datetime
.
now
().
strftime
(
"%Y-%m-%d %H:%M:%S"
)
padurlbase
=
re
.
sub
(
r
"api/1.2.9/$"
,
"p/"
,
info
[
"apiurl"
])
if
type
(
padurlbase
)
==
unicode
:
padurlbase
=
padurlbase
.
encode
(
"utf-8"
)
#
if type(padurlbase) == unicode:
#
padurlbase = padurlbase.encode("utf-8")
args
.
siteurl
=
args
.
siteurl
or
padurlbase
args
.
utcnow
=
datetime
.
utcnow
().
strftime
(
"%a, %d %b %Y %H:%M:%S +0000"
)
...
...
@@ -150,14 +159,15 @@ def main (args):
linkbase
=
args
.
linkbase
or
url_base
(
args
.
feedurl
)
# print ("linkbase", linkbase, args.linkbase, args.feedurl)
for
p
in
pads
:
for
p
in
args
.
pads
:
print
(
"p"
,
p
,
file
=
sys
.
stderr
)
versions_by_type
=
{}
p
[
"versions_by_type"
]
=
versions_by_type
for
v
in
p
[
"versions"
]:
t
=
v
[
"type"
]
versions_by_type
[
t
]
=
v
with
open
(
versions_by_type
[
"text"
][
"path"
])
as
f
:
p
[
"text"
]
=
f
.
read
()
.
decode
(
"utf-8"
)
p
[
"text"
]
=
f
.
read
()
# ADD IN LINK
for
v
in
linkversions
:
...
...
@@ -171,6 +181,6 @@ def main (args):
if
args
.
output
:
with
open
(
args
.
output
,
"w"
)
as
f
:
print
(
template
.
render
(
vars
(
args
))
.
encode
(
"utf-8"
)
,
file
=
f
)
print
(
template
.
render
(
vars
(
args
)),
file
=
f
)
else
:
print
(
template
.
render
(
vars
(
args
))
.
encode
(
"utf-8"
)
)
print
(
template
.
render
(
vars
(
args
)))
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment