Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
papersurfer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jacobsohn, Johann
papersurfer
Commits
2ab1fc1a
Commit
2ab1fc1a
authored
4 years ago
by
Johann Jacobsohn
Browse files
Options
Downloads
Patches
Plain Diff
start to try to prettify button
parent
5e1c75a6
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
papersurfer.py
+49
-27
49 additions, 27 deletions
papersurfer.py
with
49 additions
and
27 deletions
papersurfer.py
+
49
−
27
View file @
2ab1fc1a
...
...
@@ -13,12 +13,12 @@ import subprocess
from
dataclasses
import
dataclass
import
re
from
functools
import
partial
import
xml.etree.ElementTree
as
ET
import
requests
from
mattermostdriver
import
Driver
import
urwid
import
configargparse
from
pybtex.database
import
BibliographyData
,
Entry
import
xml.etree.ElementTree
as
ET
URL
=
"
mattermost.cen.uni-hamburg.de
"
CHANNEL
=
"
n5myem9yc7fyzb9am7ym5o41ry
"
...
...
@@ -32,6 +32,7 @@ class PostDTO:
reporter
:
str
doi
:
str
@dataclass
class
PaperDTO
:
""""
Encapsulate Mattermost Posts.
"""
...
...
@@ -71,15 +72,17 @@ class Doi:
headers
=
{
'
Accept
'
:
'
application/vnd.crossref.unixsd+xml
'
,
}
return
requests
.
get
(
f
'
http://dx.doi.org/
{
doi
}
'
,
headers
=
headers
).
content
return
requests
.
get
(
f
'
http://dx.doi.org/
{
doi
}
'
,
headers
=
headers
).
content
def
parse_doi_xml
(
self
,
xml
):
root
=
ET
.
fromstring
(
xml
)
author
=
root
.
find
(
"
.//{http://www.crossref.org/xschema/1.1}surname
"
).
text
# fixme
title
=
root
.
find
(
"
.//{http://www.crossref.org/xschema/1.1}title
"
).
text
journal
=
root
.
find
(
"
.//{http://www.crossref.org/xschema/1.1}full_title
"
).
text
year
=
root
.
find
(
"
.//{http://www.crossref.org/xschema/1.1}year
"
).
text
doi
=
root
.
find
(
"
.//{http://www.crossref.org/xschema/1.1}year
"
).
text
scheme
=
"
.//{http://www.crossref.org/xschema/1.1}
"
author
=
root
.
find
(
f
"
{
scheme
}
surname
"
).
text
# fixme
title
=
root
.
find
(
f
"
{
scheme
}
title
"
).
text
journal
=
root
.
find
(
f
"
{
scheme
}
full_title
"
).
text
year
=
root
.
find
(
f
"
{
scheme
}
year
"
).
text
doi
=
root
.
find
(
f
"
{
scheme
}
doi
"
).
text
return
PaperDTO
(
author
,
title
,
journal
,
year
,
doi
)
...
...
@@ -145,6 +148,25 @@ class Mattermost:
or
needle
.
lower
()
in
m
.
reporter
.
lower
()]
class
PrettyButton
(
urwid
.
Button
):
button_left
=
urwid
.
Text
(
'
[
'
)
button_right
=
urwid
.
Text
(
'
]
'
)
def
__init__
(
self
,
*
args
,
onclick
=
lambda
*
x
:
x
,
**
kwargs
):
super
(
self
.
__class__
,
self
).
__init__
(
*
args
,
**
kwargs
)
urwid
.
connect_signal
(
self
,
'
click
'
,
onclick
)
def
button
(
self
,
label
,
onclick
):
"""
Render a pretty button.
"""
btn
=
urwid
.
Button
(
label
)
urwid
.
connect_signal
(
btn
,
'
click
'
,
onclick
)
wrapper
=
urwid
.
AttrMap
(
btn
,
''
,
'
highlight
'
)
padding
=
urwid
.
Padding
(
wrapper
,
left
=
4
,
right
=
4
)
return
padding
,
btn
class
Papersurfer
:
"""
Provide UI and interface with mattermost class.
"""
def
__init__
(
self
,
username
,
password
):
...
...
@@ -154,10 +176,13 @@ class Papersurfer:
palette
=
[
(
'
I say
'
,
'
default,bold
'
,
'
default
'
,
'
bold
'
),
(
'
needle
'
,
'
default, bold, underline
'
,
'
default
'
,
'
bold
'
)]
(
'
needle
'
,
'
default, bold, underline
'
,
'
default
'
,
'
bold
'
),
(
'
highlight
'
,
'
black
'
,
'
dark blue
'
),
]
ask
=
urwid
.
Edit
((
'
I say
'
,
u
"
Filter?
\n
"
))
exitbutton
=
urwid
.
Button
(
u
'
Exit
'
)
self
.
exportbutton
=
urwid
.
Button
(
u
'
Export filtered list as bibtex
'
)
exitbutton
=
PrettyButton
(
u
'
Exit
'
,
onclick
=
self
.
on_exit_clicked
)
self
.
exportbutton
=
PrettyButton
(
u
'
Export filtered list as bibtex
'
,
onclick
=
self
.
on_export_clicked
)
div
=
urwid
.
Divider
(
u
'
-
'
)
self
.
mtm
=
Mattermost
(
username
,
password
)
...
...
@@ -172,8 +197,6 @@ class Papersurfer:
top
=
urwid
.
Filler
(
pile
,
valign
=
'
middle
'
)
urwid
.
connect_signal
(
ask
,
'
change
'
,
self
.
onchange
)
urwid
.
connect_signal
(
exitbutton
,
'
click
'
,
self
.
on_exit_clicked
)
urwid
.
connect_signal
(
self
.
exportbutton
,
'
click
'
,
self
.
on_export_clicked
)
self
.
mainloop
=
urwid
.
MainLoop
(
top
,
palette
)
self
.
mainloop
.
run
()
...
...
@@ -191,18 +214,17 @@ class Papersurfer:
text_items
.
append
((
'
needle
'
,
needles
[
i
]))
title
=
urwid
.
Text
(
text_items
)
discuss_button
=
urwid
.
Button
(
"
Open Discussion
"
)
doi_button
=
urwid
.
Button
(
"
Open DOI
"
)
discuss_button
=
PrettyButton
(
"
Open Discussion
"
,
onclick
=
partial
(
self
.
h_open_discussion
,
paper
))
doi_button
=
PrettyButton
(
"
Open DOI
"
,
onclick
=
partial
(
self
.
h_open_doi
,
paper
))
button_bar
=
urwid
.
Columns
([
discuss_button
,
doi_button
])
urwid
.
connect_signal
(
discuss_button
,
'
click
'
,
partial
(
self
.
h_open_discussion
,
paper
))
urwid
.
connect_signal
(
doi_button
,
'
click
'
,
partial
(
self
.
h_open_doi
,
paper
))
pile
=
urwid
.
Pile
([
title
,
button_bar
,
urwid
.
Divider
()])
return
pile
def
updscrn
(
self
):
""""
Update (redraw) screen.
"""
self
.
mainloop
.
draw_screen
()
def
onchange
(
self
,
_
,
needle
):
...
...
@@ -236,8 +258,8 @@ class Papersurfer:
papers
=
self
.
mtm
.
get_filtered
(
self
.
filter
)
dois
=
[
paper
.
doi
for
paper
in
papers
]
string
=
Bibtex
().
bib_from_dois
(
dois
)
with
open
(
"
export.bib
"
,
'
w
'
)
as
f
:
f
.
write
(
string
)
with
open
(
"
export.bib
"
,
'
w
'
)
as
f
ile
:
f
ile
.
write
(
string
)
def
h_open_discussion
(
self
,
post
,
_
):
"""
Handle click/enter on discussion button.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment