Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
weboob
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
177
Issues
177
List
Boards
Labels
Milestones
Merge Requests
52
Merge Requests
52
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
weboob
weboob
Commits
70641b6e
Commit
70641b6e
authored
Jul 27, 2013
by
Romain Bignon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new application parceloob
parent
5c95363a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
209 additions
and
0 deletions
+209
-0
scripts/parceloob
scripts/parceloob
+27
-0
weboob/applications/parceloob/__init__.py
weboob/applications/parceloob/__init__.py
+23
-0
weboob/applications/parceloob/parceloob.py
weboob/applications/parceloob/parceloob.py
+159
-0
No files found.
scripts/parceloob
0 → 100755
View file @
70641b6e
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
# Copyright(C) 2013 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from
weboob.applications.parceloob
import
Parceloob
if
__name__
==
'__main__'
:
Parceloob
.
run
()
weboob/applications/parceloob/__init__.py
0 → 100644
View file @
70641b6e
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from
.parceloob
import
Parceloob
__all__
=
[
'Parceloob'
]
weboob/applications/parceloob/parceloob.py
0 → 100644
View file @
70641b6e
# -*- coding: utf-8 -*-
# Copyright(C) 2013 Romain Bignon
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import
sys
from
weboob.capabilities.base
import
empty
from
weboob.capabilities.parcel
import
ICapParcel
,
Parcel
from
weboob.tools.application.repl
import
ReplApplication
from
weboob.tools.application.formatters.iformatter
import
IFormatter
__all__
=
[
'Parceloob'
]
STATUS
=
{
Parcel
.
STATUS_PLANNED
:
(
'PLANNED'
,
'red'
),
Parcel
.
STATUS_IN_TRANSIT
:
(
'IN TRANSIT'
,
'yellow'
),
Parcel
.
STATUS_ARRIVED
:
(
'ARRIVED'
,
'green'
),
Parcel
.
STATUS_UNKNOWN
:
(
''
,
'white'
),
}
class
HistoryFormatter
(
IFormatter
):
MANDATORY_FIELDS
=
()
def
format_obj
(
self
,
obj
,
alias
):
if
isinstance
(
obj
,
Parcel
):
result
=
u'Parcel
%
s (
%
s)
\n
'
%
(
self
.
colored
(
obj
.
id
,
'red'
,
'bold'
),
self
.
colored
(
obj
.
backend
,
'blue'
,
'bold'
))
result
+=
u'
%
sArrival:
%
s
%
s
\n
'
%
(
self
.
BOLD
,
self
.
NC
,
obj
.
arrival
)
status
,
status_color
=
STATUS
[
obj
.
status
]
result
+=
u'
%
sStatus:
%
s
%
s
\n
'
%
(
self
.
BOLD
,
self
.
NC
,
self
.
colored
(
status
,
status_color
))
result
+=
u'
%
sInfo:
%
s
%
s
\n\n
'
%
(
self
.
BOLD
,
self
.
NC
,
obj
.
info
)
result
+=
u' Date Location Activity
\n
'
result
+=
u'---------------------+-----------------+---------------------------------------------------
\n
'
return
result
return
'
%
s
%
s
%
s'
%
(
self
.
colored
(
'
%-19
s'
%
obj
.
date
,
'blue'
),
self
.
colored
(
'
%-17
s'
%
obj
.
location
,
'magenta'
),
self
.
colored
(
obj
.
activity
,
'yellow'
))
class
StatusFormatter
(
IFormatter
):
MANDATORY_FIELDS
=
(
'id'
,)
def
format_obj
(
self
,
obj
,
alias
):
if
alias
is
not
None
:
id
=
'
%
s (
%
s)'
%
(
self
.
colored
(
'
%3
s'
%
(
'#'
+
alias
),
'red'
,
'bold'
),
self
.
colored
(
obj
.
backend
,
'blue'
,
'bold'
))
clean
=
'#
%
s (
%
s)'
%
(
alias
,
obj
.
backend
)
if
len
(
clean
)
<
15
:
id
+=
(
' '
*
(
15
-
len
(
clean
)))
else
:
id
=
self
.
colored
(
'
%30
s'
%
obj
.
fullid
,
'red'
,
'bold'
)
status
,
status_color
=
STATUS
[
obj
.
status
]
arrival
=
obj
.
arrival
.
strftime
(
'
%
Y-
%
m-
%
d'
)
if
not
empty
(
obj
.
arrival
)
else
''
result
=
u'
%
s
%
s
%
s
%
s
%
s'
%
(
id
,
self
.
colored
(
u'—'
,
'cyan'
),
self
.
colored
(
'
%-10
s'
%
status
,
status_color
),
self
.
colored
(
'
%-10
s'
%
arrival
,
'blue'
),
self
.
colored
(
'
%-20
s'
%
obj
.
info
,
'yellow'
))
return
result
class
Parceloob
(
ReplApplication
):
APPNAME
=
'parceloob'
VERSION
=
'0.g'
COPYRIGHT
=
'Copyright(C) 2013 Romain Bignon'
CAPS
=
ICapParcel
DESCRIPTION
=
"Console application to track your parcels."
SHORT_DESCRIPTION
=
"manage your parcels"
EXTRA_FORMATTERS
=
{
'status'
:
StatusFormatter
,
'history'
:
HistoryFormatter
,
}
DEFAULT_FORMATTER
=
'table'
COMMANDS_FORMATTERS
=
{
'status'
:
'status'
,
'info'
:
'history'
,
}
STORAGE
=
{
'tracking'
:
[]}
def
do_track
(
self
,
line
):
"""
track ID
Track a parcel.
"""
parcel
=
self
.
get_object
(
line
,
'get_parcel_tracking'
)
if
not
parcel
:
print
>>
sys
.
stderr
,
'Error: the parcel "
%
s" is not found'
%
line
return
2
parcels
=
set
(
self
.
storage
.
get
(
'tracking'
,
default
=
[]))
parcels
.
add
(
parcel
.
fullid
)
self
.
storage
.
set
(
'tracking'
,
list
(
parcels
))
self
.
storage
.
save
()
print
'Parcel "
%
s" has been tracked.'
%
parcel
.
fullid
def
do_untrack
(
self
,
line
):
"""
untrack ID
Stop tracking a parcel.
"""
parcel
=
self
.
get_object
(
line
,
'get_parcel_tracking'
)
if
not
parcel
:
print
>>
sys
.
stderr
,
'Error: the parcel "
%
s" is not found'
%
line
return
2
parcels
=
set
(
self
.
storage
.
get
(
'tracking'
,
default
=
[]))
try
:
parcels
.
remove
(
parcel
.
fullid
)
except
KeyError
:
print
>>
sys
.
stderr
,
"Error: parcel
\"
%
s
\"
wasn't tracked"
%
parcel
.
fullid
return
2
self
.
storage
.
set
(
'tracking'
,
list
(
parcels
))
self
.
storage
.
save
()
print
"Parcel
\"
%
s
\"
isn't tracked anymore."
%
parcel
.
fullid
def
do_status
(
self
,
line
):
"""
status
Display status for all of the tracked parcels.
"""
self
.
start_format
()
for
id
in
self
.
storage
.
get
(
'tracking'
,
default
=
[]):
p
=
self
.
get_object
(
id
,
'get_parcel_tracking'
)
if
p
is
None
:
continue
self
.
cached_format
(
p
)
def
do_info
(
self
,
id
):
parcel
=
self
.
get_object
(
id
,
'get_parcel_tracking'
,
[])
if
not
parcel
:
print
>>
sys
.
stderr
,
'Error: parcel not found'
return
2
self
.
start_format
()
self
.
format
(
parcel
)
for
event
in
parcel
.
history
:
self
.
format
(
event
)
Write
Preview
Markdown
is supported
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