move scripts into topdir scripts/ directory
This commit is contained in:
parent
1540932542
commit
3fcb0eb8f2
7 changed files with 26 additions and 64 deletions
79
scripts/boobank
Executable file
79
scripts/boobank
Executable file
|
|
@ -0,0 +1,79 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
"""
|
||||
Copyright(C) 2009-2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import with_statement
|
||||
|
||||
import sys
|
||||
|
||||
import weboob
|
||||
from weboob.capabilities.bank import ICapBank, AccountNotFound
|
||||
from weboob.tools.application import ConsoleApplication
|
||||
|
||||
class Boobank(ConsoleApplication):
|
||||
APPNAME = 'boobank'
|
||||
|
||||
def main(self, argv):
|
||||
self.weboob.load_backends(ICapBank)
|
||||
|
||||
return self.process_command(*argv[1:])
|
||||
|
||||
@ConsoleApplication.command('List every available accounts')
|
||||
def command_list(self):
|
||||
lines = [' ID Account Balance Coming ',
|
||||
'+-----------------+---------------------+--------------+-------------+']
|
||||
for name, backend, in self.weboob.iter_backends():
|
||||
try:
|
||||
for account in backend.iter_accounts():
|
||||
lines.append('%17s %-20s %11.2f %11.2f' % (
|
||||
account.id, account.label, account.balance, account.coming))
|
||||
except weboob.tools.browser.BrowserIncorrectPassword:
|
||||
print >>sys.stderr, 'Error: Incorrect password for backend %s' % name
|
||||
return 1
|
||||
print '\n'.join(lines)
|
||||
|
||||
@ConsoleApplication.command('Display all future operations')
|
||||
def command_coming(self, id):
|
||||
operations = []
|
||||
found = 0
|
||||
for name, backend in self.weboob.iter_backends():
|
||||
try:
|
||||
account = backend.get_account(id)
|
||||
except AccountNotFound:
|
||||
if found == 0:
|
||||
found = -1
|
||||
else:
|
||||
found = 1
|
||||
for operation in backend.iter_operations(account):
|
||||
operations.append(' %8s %-50s %11.2f' % (operation.date, operation.label, operation.amount))
|
||||
if found < 0:
|
||||
print >>sys.stderr, "Error: account %s not found" % id
|
||||
return 1
|
||||
else:
|
||||
if operations:
|
||||
print ' Date Label Amount '
|
||||
print '+----------+----------------------------------------------------+-------------+'
|
||||
print '\n'.join(operations)
|
||||
else:
|
||||
print 'No coming operations for ID=%s' % id
|
||||
|
||||
if __name__ == '__main__':
|
||||
Boobank.run()
|
||||
59
scripts/dummy
Executable file
59
scripts/dummy
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from weboob.capabilities.bank import ICapBank
|
||||
from weboob.capabilities.messages import ICapMessages, ICapMessagesReply
|
||||
from weboob.capabilities.travel import ICapTravel
|
||||
from weboob.tools.application import BaseApplication
|
||||
|
||||
class Application(BaseApplication):
|
||||
APPNAME = 'dummy'
|
||||
|
||||
def main(self, argv):
|
||||
self.weboob.load_backends()
|
||||
|
||||
for name, backend in self.weboob.iter_backends():
|
||||
print 'Backend [%s]' % name
|
||||
if backend.has_caps(ICapMessages):
|
||||
print '|- ICapMessages [Print its messages]'
|
||||
for message in backend.iter_messages():
|
||||
print '| |- %s' % message
|
||||
if backend.has_caps(ICapMessagesReply):
|
||||
print '|- ICapMessagesReply [TODO]'
|
||||
if backend.has_caps(ICapTravel):
|
||||
print '|- ICapTravel.stations [Search station \'defense\']'
|
||||
s = None
|
||||
for station in backend.iter_station_search('defense'):
|
||||
print '| |- [%s] %s' % (station.id, station.name)
|
||||
if s is None:
|
||||
s = station.id
|
||||
print '|- ICapTravel.departures [Departures from \'%s\']' % s
|
||||
for departure in backend.iter_station_departures(s):
|
||||
print '| |- [%s] %s at %s to %s' % (departure.id, departure.type, departure.time.strftime("%H:%M"),
|
||||
departure.arrival_station)
|
||||
if backend.has_caps(ICapBank):
|
||||
for account in backend.iter_accounts():
|
||||
print '| |- [%s] label=%s balance=%s coming=%s' % (
|
||||
account.id, account.label, account.balance, account.coming)
|
||||
|
||||
if __name__ == '__main__':
|
||||
Application.run()
|
||||
26
scripts/http
Executable file
26
scripts/http
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Christophe Benz
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from weboob.frontends.http import HTTPApplication
|
||||
|
||||
if __name__ == '__main__':
|
||||
HTTPApplication.run()
|
||||
132
scripts/monboob
Executable file
132
scripts/monboob
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from email.mime.text import MIMEText
|
||||
from smtplib import SMTP
|
||||
from email.Header import Header
|
||||
from email.Utils import parseaddr, formataddr
|
||||
import time
|
||||
import sys
|
||||
from html2text import html2text
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages
|
||||
from weboob.tools.application import BaseApplication
|
||||
|
||||
class Monboob(BaseApplication):
|
||||
APPNAME = 'monboob'
|
||||
CONFIG = {'interval': 15,
|
||||
'domain': 'weboob.example.org',
|
||||
'recipient': 'weboob@example.org',
|
||||
'smtp': 'localhost',
|
||||
'html': False}
|
||||
|
||||
def main(self, argv):
|
||||
self.load_config()
|
||||
if not self.config:
|
||||
print >>sys.stderr, "Error: %s is not configured yet. Please call 'monboob -c'" % argv[0]
|
||||
print >>sys.stderr, "Also, you need to use 'weboobcfg' to set backend configs"
|
||||
return -1
|
||||
|
||||
self.weboob.load_backends(ICapMessages, storage=self.create_storage())
|
||||
|
||||
self.weboob.repeat(self.config.get('interval'), self.process)
|
||||
self.weboob.loop()
|
||||
|
||||
def process(self):
|
||||
for name, backend in self.weboob.iter_backends():
|
||||
for message in backend.iter_new_messages():
|
||||
self.send_email(backend, message)
|
||||
|
||||
def send_email(self, backend, mail):
|
||||
domain = self.config.get('domain')
|
||||
recipient = self.config.get('recipient')
|
||||
|
||||
reply_id = ''
|
||||
if mail.get_reply_id():
|
||||
reply_id = u'<%s.%s@%s>' % (backend.name, mail.get_full_reply_id(), domain)
|
||||
subject = mail.get_title()
|
||||
sender = u'%s <%s@%s>' % (mail.get_from(), backend.name, domain)
|
||||
|
||||
# assume that get_date() returns an UTC datetime
|
||||
date = time.strftime('%a, %d %b %Y %H:%M:%S +0000', mail.get_date().timetuple())
|
||||
msg_id = u'<%s.%s@%s>' % (backend.name, mail.get_full_id(), domain)
|
||||
|
||||
if self.config.get('html'):
|
||||
body = mail.get_content()
|
||||
content_type = 'html'
|
||||
else:
|
||||
body = html2text(mail.get_content())
|
||||
content_type = 'plain'
|
||||
|
||||
if mail.get_signature():
|
||||
if self.config.get('html'):
|
||||
body += u'<p>-- <br />%s</p>' % mail.get_signature()
|
||||
else:
|
||||
body += u'\n\n-- \n'
|
||||
body += html2text(mail.get_signature())
|
||||
|
||||
# Header class is smart enough to try US-ASCII, then the charset we
|
||||
# provide, then fall back to UTF-8.
|
||||
header_charset = 'ISO-8859-1'
|
||||
|
||||
# We must choose the body charset manually
|
||||
for body_charset in 'US-ASCII', 'ISO-8859-1', 'UTF-8':
|
||||
try:
|
||||
body.encode(body_charset)
|
||||
except UnicodeError:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
|
||||
# Split real name (which is optional) and email address parts
|
||||
sender_name, sender_addr = parseaddr(sender)
|
||||
recipient_name, recipient_addr = parseaddr(recipient)
|
||||
|
||||
# We must always pass Unicode strings to Header, otherwise it will
|
||||
# use RFC 2047 encoding even on plain ASCII strings.
|
||||
sender_name = str(Header(unicode(sender_name), header_charset))
|
||||
recipient_name = str(Header(unicode(recipient_name), header_charset))
|
||||
|
||||
# Make sure email addresses do not contain non-ASCII characters
|
||||
sender_addr = sender_addr.encode('ascii')
|
||||
recipient_addr = recipient_addr.encode('ascii')
|
||||
|
||||
# Create the message ('plain' stands for Content-Type: text/plain)
|
||||
msg = MIMEText(body.encode(body_charset), content_type, body_charset)
|
||||
msg['From'] = formataddr((sender_name, sender_addr))
|
||||
msg['To'] = formataddr((recipient_name, recipient_addr))
|
||||
msg['Subject'] = Header(unicode(subject), header_charset)
|
||||
msg['Message-Id'] = msg_id
|
||||
msg['Date'] = date
|
||||
if reply_id:
|
||||
msg['In-Reply-To'] = reply_id
|
||||
|
||||
# Send the message via SMTP to localhost:25
|
||||
smtp = SMTP(self.config.get('smtp'))
|
||||
print 'Send mail from <%s> to <%s>' % (sender, recipient)
|
||||
smtp.sendmail(sender, recipient, msg.as_string())
|
||||
smtp.quit()
|
||||
|
||||
return msg['Message-Id']
|
||||
|
||||
if __name__ == '__main__':
|
||||
Monboob.run()
|
||||
26
scripts/travel
Executable file
26
scripts/travel
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from weboob.frontends.travel import Travel
|
||||
|
||||
if __name__ == '__main__':
|
||||
Travel.run()
|
||||
26
scripts/weboobcfg
Executable file
26
scripts/weboobcfg
Executable file
|
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=python et softtabstop=4 cinoptions=4 shiftwidth=4 ts=4 ai
|
||||
|
||||
"""
|
||||
Copyright(C) 2010 Romain Bignon
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, version 3 of the License.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
"""
|
||||
|
||||
from weboob.frontends.weboobcfg import WeboobCfg
|
||||
|
||||
if __name__ == '__main__':
|
||||
WeboobCfg.run()
|
||||
Loading…
Add table
Add a link
Reference in a new issue