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
0cd9f456
Commit
0cd9f456
authored
Aug 3, 2020
by
Johann Jacobsohn
Browse files
Options
Downloads
Patches
Plain Diff
initial import
parent
b4e4c1f0
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+5
-1
5 additions, 1 deletion
README.md
papersurfer.py
+116
-0
116 additions, 0 deletions
papersurfer.py
screencast.gif
+0
-0
0 additions, 0 deletions
screencast.gif
with
121 additions
and
1 deletion
README.md
+
5
−
1
View file @
0cd9f456
#
p
apersurfer
#
P
apersurfer
Automatically download paper list from Mattermost channel and display.

This diff is collapsed.
Click to expand it.
papersurfer.py
0 → 100644
+
116
−
0
View file @
0cd9f456
""""
Paper surfer - browse papers posted on the mattermost channel.
UI:
[____(filter)______]
1. paper (open discussion) (open paper)
2. paper (open discussion) (open paper)
3. paper (open discussion) (open paper)
4. paper (open discussion) (open paper)
"""
from
dataclasses
import
dataclass
from
mattermostdriver
import
Driver
import
urwid
import
configargparse
URL
=
"
mattermost.cen.uni-hamburg.de
"
CHANNEL
=
"
n5myem9yc7fyzb9am7ym5o41ry
"
@dataclass
class
PostDTO
:
""""
Encapsulate Mattermost Posts.
"""
message
:
str
class
Mattermost
:
"""
Provide a simplified interaction w/ mattermost api.
"""
def
__init__
(
self
,
username
,
password
):
self
.
mattermost
=
Driver
({
'
url
'
:
URL
,
'
login_id
'
:
username
,
'
password
'
:
password
,
'
port
'
:
443
})
self
.
mattermost
.
login
()
def
retrieve_all_messages
(
self
):
"""
Retrieve all messages from mattermost, unfiltered for papers.
"""
posts
=
self
.
mattermost
.
posts
.
get_posts_for_channel
(
CHANNEL
)
return
[
PostDTO
(
m
[
'
message
'
])
for
m
in
posts
[
'
posts
'
].
values
()]
def
filter_incoming
(
self
,
posts
):
"""
Filter messages from mattermost to only papers.
"""
return
[
p
for
p
in
posts
if
"
doi
"
in
p
.
message
]
def
retrieve
(
self
):
"""
Retrieve papers from mattermost channel.
"""
msgs
=
self
.
retrieve_all_messages
()
self
.
msgs
=
self
.
filter_incoming
(
msgs
)
return
self
.
msgs
def
get_filtered
(
self
,
needle
):
"""
Filter posts by needle.
"""
return
[
m
for
m
in
self
.
msgs
if
needle
.
lower
()
in
m
.
message
.
lower
()]
class
Papersurfer
:
"""
Provide UI and interface with mattermost class.
"""
def
__init__
(
self
,
username
,
password
):
palette
=
[(
'
I say
'
,
'
default,bold
'
,
'
default
'
,
'
bold
'
)]
ask
=
urwid
.
Edit
((
'
I say
'
,
u
"
Filter?
\n
"
))
exitbutton
=
urwid
.
Button
(
u
'
Exit
'
)
div
=
urwid
.
Divider
(
u
'
-
'
)
self
.
mtm
=
Mattermost
(
username
,
password
)
papers
=
[
msg
.
message
for
msg
in
self
.
mtm
.
retrieve
()]
body
=
[]
for
paper
in
papers
:
button
=
urwid
.
Button
(
paper
)
body
.
append
(
urwid
.
AttrMap
(
button
,
None
,
focus_map
=
'
reversed
'
))
self
.
listcontent
=
urwid
.
SimpleFocusListWalker
(
body
)
paperlist
=
urwid
.
BoxAdapter
(
urwid
.
ListBox
(
self
.
listcontent
),
40
)
pile
=
urwid
.
Pile
([
ask
,
div
,
paperlist
,
div
,
exitbutton
])
top
=
urwid
.
Filler
(
pile
,
valign
=
'
middle
'
)
urwid
.
connect_signal
(
ask
,
'
change
'
,
self
.
onchange
)
urwid
.
connect_signal
(
exitbutton
,
'
click
'
,
self
.
on_exit_clicked
)
urwid
.
MainLoop
(
top
,
palette
).
run
()
def
onchange
(
self
,
_
,
new_edit_text
):
"""
Handle filter change.
"""
papers
=
[
msg
.
message
for
msg
in
self
.
mtm
.
get_filtered
(
new_edit_text
)]
self
.
listcontent
.
clear
()
for
paper
in
papers
:
button
=
urwid
.
Button
(
paper
)
self
.
listcontent
.
append
(
urwid
.
AttrMap
(
button
,
None
,
focus_map
=
'
reversed
'
))
def
on_exit_clicked
(
self
,
button
):
"""
Handle exitbutton click and exit.
"""
raise
urwid
.
ExitMainLoop
()
def
parse_args
():
"""
Parse command line arguments and config file.
"""
parser
=
configargparse
.
ArgParser
()
parser
.
add
(
"
-w
"
,
"
--write-out-config-file
"
,
help
=
"
takes the current command line args and writes them out
"
"
to a config file at the given path
"
,
is_write_out_config_file_arg
=
True
)
parser
.
add
(
'
-c
'
,
'
--my-config
'
,
required
=
False
,
is_config_file
=
True
,
help
=
'
config file path
'
,
default
=
'
papersurfer.conf
'
)
parser
.
add
(
'
-u
'
,
'
--username
'
,
required
=
True
,
help
=
'
Mattermost username
'
,
default
=
"
USERNAME
"
)
parser
.
add
(
'
-p
'
,
'
--password
'
,
required
=
True
,
help
=
'
Mattermost password
'
,
default
=
"
PASSWORD
"
)
options
=
parser
.
parse_args
()
return
options
.
username
,
options
.
password
if
__name__
==
"
__main__
"
:
USERNAME
,
PASSWORD
=
parse_args
()
Papersurfer
(
USERNAME
,
PASSWORD
)
This diff is collapsed.
Click to expand it.
screencast.gif
0 → 100644
+
0
−
0
View file @
0cd9f456
437 KiB
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