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
076b06dd
Commit
076b06dd
authored
4 years ago
by
Johann Jacobsohn
Browse files
Options
Downloads
Patches
Plain Diff
add options to dump posts and bib to stdout for lolcat
parent
3026921d
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/papersurfer.py
+76
-51
76 additions, 51 deletions
papersurfer/papersurfer.py
with
76 additions
and
51 deletions
papersurfer/papersurfer.py
+
76
−
51
View file @
076b06dd
...
...
@@ -34,6 +34,9 @@ class PostDTO:
reporter
:
str
doi
:
str
def
__str__
(
self
):
return
self
.
message
@dataclass
class
PaperDTO
:
...
...
@@ -522,55 +525,6 @@ def interactive_configuration():
return url, channel, username, password
def parse_args():
"""
Parse command line arguments and config file.
"""
parser = configargparse.ArgParser()
parser._default_config_files = get_config_file_paths()
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
'
)
parser.add(
'
--
url
'
, required=False, help=
'
Mattermost
url
'
)
parser.add(
'
--
channel
'
, required=False, help=
'
Mattermost
channel
'
)
parser.add(
'
-
u
'
,
'
--
username
'
, required=False, help=
'
Mattermost
username
'
)
parser.add(
'
-
p
'
,
'
--
password
'
, required=False, help=
'
Mattermost
password
'
)
options = parser.parse_args()
if not options.url:
start_interactive = input(
"
Could not load config file or read command line arguments, do you
"
"
wish to start the interactive configuration assistant? (y/n)
"
)
if start_interactive ==
"
y
"
:
url, channel, username, password = interactive_configuration()
try:
Mattermost(url, channel, username, password)
except ConfigError:
print(
"
Failed to validate configuration, exiting.
"
)
exit(1)
options.url = url
options.channel = channel
options.username = username
options.password = password
configfile =
"
papersurfer.conf
"
with open(configfile,
"
w
"
) as file:
file.write(f
"
url = {url}
\n
"
)
file.write(f
"
channel = {channel}
\n
"
)
file.write(f
"
username = {username}
\n
"
)
file.write(f
"
password = {password}
\n
"
)
print(f
"
Configfile {configfile} written.
"
)
time.sleep(2)
else:
parser.print_help()
exit(0)
return options.url, options.channel, options.username, options.password
class PostDialog(urwid.WidgetWrap):
"""
UI:
...
...
@@ -646,9 +600,80 @@ class PostDialog(urwid.WidgetWrap):
self.doi_result.set_text(
"
invalid doi
"
)
def parse_args():
"""
Parse command line arguments and config file.
"""
parser = configargparse.ArgParser()
parser._default_config_files = get_config_file_paths()
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
'
)
parser.add(
'
--
url
'
, required=False, help=
'
Mattermost
url
'
)
parser.add(
'
--
channel
'
, required=False, help=
'
Mattermost
channel
'
)
parser.add(
'
-
u
'
,
'
--
username
'
, required=False, help=
'
Mattermost
username
'
)
parser.add(
'
-
p
'
,
'
--
password
'
, required=False, help=
'
Mattermost
password
'
)
parser.add(
'
--
dump
-
posts
'
, action=
'
store_true
'
,
help=
"
Dump mattermost paper posts to stdout and exit
"
)
parser.add(
'
--
dump
-
bibtex
'
, action=
'
store_true
'
,
help=
"
Dump mattermost paper posts to stdout and exit
"
)
options = parser.parse_args()
if not options.url:
start_interactive = input(
"
Could not load config file or read command line arguments, do you
"
"
wish to start the interactive configuration assistant? (y/n)
"
)
if start_interactive ==
"
y
"
:
url, channel, username, password = interactive_configuration()
try:
Mattermost(url, channel, username, password)
except ConfigError:
print(
"
Failed to validate configuration, exiting.
"
)
exit(1)
options.url = url
options.channel = channel
options.username = username
options.password = password
configfile =
"
papersurfer.conf
"
with open(configfile,
"
w
"
) as file:
file.write(f
"
url = {url}
\n
"
)
file.write(f
"
channel = {channel}
\n
"
)
file.write(f
"
username = {username}
\n
"
)
file.write(f
"
password = {password}
\n
"
)
print(f
"
Configfile {configfile} written.
"
)
time.sleep(2)
else:
parser.print_help()
exit(0)
return options
def just_papers(url, channel, username, password):
"""
Fuck off with all this interactive shit.
"""
posts = Mattermost(url, channel, username, password).retrieve()
for post in posts:
print(post)
def just_bibtex(url, channel, username, password):
posts = Mattermost(url, channel, username, password).retrieve()
dois = [post.doi for post in posts]
print(Bibtex().bib_from_dois(dois))
def main():
URL, CHANNEL, USERNAME, PASSWORD = parse_args()
Papersurfer(URL, CHANNEL, USERNAME, PASSWORD)
opt = parse_args()
if opt.dump_posts:
just_papers(opt.url, opt.channel, opt.username, opt.password)
if opt.dump_bibtex:
just_bibtex(opt.url, opt.channel, opt.username, opt.password)
else:
Papersurfer(opt.url, opt.channel, opt.username, opt.password)
if __name__ ==
"
__main__
"
:
...
...
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