ovs: restrict conf choices and let browser fetch cities list
This commit is contained in:
parent
46f61b3516
commit
4ee3460b01
3 changed files with 33 additions and 4 deletions
|
|
@ -28,6 +28,9 @@ from .browser import OvsBrowser
|
|||
__all__ = ['OvsBackend']
|
||||
|
||||
|
||||
CITIES = {u'agen': u'Agen', u'ajaccio': u'Ajaccio', u'albi': u'Albi', u'amiens': u'Amiens', u'angers': u'Angers', u'angouleme': u'Angoul\xeame', u'annecy': u'Annecy', u'aurillac': u'Aurillac', u'auxerre': u'Auxerre', u'avignon': u'Avignon', u'bastia': u'Bastia', u'beauvais': u'Beauvais', u'belfort': u'Belfort', u'bergerac': u'Bergerac', u'besancon': u'Besan\xe7on', u'beziers': u'B\xe9ziers', u'biarritz': u'Biarritz', u'blois': u'Blois', u'bordeaux': u'Bordeaux', u'bourg-en-bresse': u'M\xe2con', u'bourges': u'Bourges', u'brest': u'Brest', u'brive-la-gaillarde': u'Brive', u'bruxelles': u'Bruxelles', u'caen': u'Caen', u'calais': u'Boulogne', u'carcassonne': u'Carcassonne', u'chalon-sur-saone': u'Chalon', u'chambery': u'Albertville', u'chantilly': u'Chantilly', u'charleroi': u'Charleroi', u'charleville-mezieres': u'Charleville', u'chartres': u'Chartres', u'chateauroux': u'Ch\xe2teauroux', u'cherbourg': u'Cherbourg', u'cholet': u'Cholet', u'clermont-ferrand': u'Clt-Ferrand', u'compiegne': u'Compi\xe8gne', u'dieppe': u'Dieppe', u'dijon': u'Dijon', u'dunkerque': u'Dunkerque', u'evreux': u'Evreux', u'frejus': u'Fr\xe9jus', u'gap': u'Gap', u'geneve': u'Gen\xe8ve', u'grenoble': u'Grenoble', u'la-roche-sur-yon': u'La Roche/Yon', u'la-rochelle': u'La Rochelle', u'lausanne': u'Lausanne', u'laval': u'Laval', u'le-havre': u'Le Havre', u'le-mans': u'Alen\xe7on', u'liege': u'Li\xe8ge', u'lille': u'Lille', u'limoges': u'Limoges', u'lorient': u'Lorient', u'luxembourg': u'Luxembourg', u'lyon': u'Lyon', u'marseille': u'Aix', u'metz': u'Metz', u'mons': u'Mons', u'mont-de-marsan': u'Mont de Marsan', u'montauban': u'Montauban', u'montlucon': u'Montlu\xe7on', u'montpellier': u'Montpellier', u'mulhouse': u'Colmar', u'namur': u'Namur', u'nancy': u'Nancy', u'nantes': u'Nantes', u'nevers': u'Nevers', u'nice': u'Cannes', u'nimes': u'N\xeemes', u'niort': u'Niort', u'orleans': u'Orl\xe9ans', u'paris': u'PARIS', u'pau': u'Pau', u'perigueux': u'P\xe9rigueux', u'perpignan': u'Perpignan', u'poitiers': u'Poitiers', u'quimper': u'Quimper', u'reims': u'Reims', u'rennes': u'Rennes', u'roanne': u'Roanne', u'rodez': u'Rodez', u'rouen': u'Rouen', u'saint-brieuc': u'St-Brieuc', u'saint-etienne': u'St-Etienne', u'saint-malo': u'St-Malo', u'saint-nazaire': u'St-Nazaire', u'saint-quentin': u'St-Quentin', u'saintes': u'Saintes', u'strasbourg': u'Strasbourg', u'tarbes': u'Tarbes', u'toulon': u'Toulon', u'toulouse': u'Toulouse', u'tours': u'Tours', u'troyes': u'Troyes', u'valence': u'Mont\xe9limar', u'vannes': u'Vannes', u'zurich': u'Zurich'}
|
||||
|
||||
|
||||
class OvsBackend(BaseBackend, ICapMessages, ICapMessagesPost):
|
||||
NAME = 'ovs'
|
||||
DESCRIPTION = u'OnVaSortir website. Handles private messages only'
|
||||
|
|
@ -37,8 +40,7 @@ class OvsBackend(BaseBackend, ICapMessages, ICapMessagesPost):
|
|||
|
||||
CONFIG = BackendConfig(Value('username', label='Username', default=''),
|
||||
ValueBackendPassword('password', label='Password', default=''),
|
||||
Value('city', label='City (subdomain)', default='paris'))
|
||||
# TODO keep list of possible cities
|
||||
Value('city', label='City (subdomain)', default='paris', choices=CITIES))
|
||||
|
||||
BROWSER = OvsBrowser
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from weboob.tools.browser import BaseBrowser, BrowserIncorrectPassword
|
|||
from weboob.tools.parsers.iparser import IParser
|
||||
import BeautifulSoup
|
||||
|
||||
from .pages import PagePrivateThreadsList, PagePrivateThread, PageLogin, PageIndex, DummyPage, PageUserProfile
|
||||
from .pages import PagePrivateThreadsList, PagePrivateThread, PageLogin, PageIndex, DummyPage, PageUserProfile, PageCityList
|
||||
|
||||
|
||||
__all__ = ['OvsBrowser']
|
||||
|
|
@ -57,6 +57,8 @@ class OvsBrowser(BaseBrowser):
|
|||
'%s://%s/message_action_envoi.php' % (self.PROTOCOL, self.DOMAIN): DummyPage,
|
||||
|
||||
r'%s://%s/profil_read.php\?.+' % (self.PROTOCOL, self.DOMAIN): PageUserProfile,
|
||||
'http://www.onvasortir.com/?': PageCityList,
|
||||
'http://www.urbeez.com/?': PageCityList,
|
||||
}
|
||||
|
||||
kw['parser'] = SoupParser()
|
||||
|
|
@ -100,3 +102,14 @@ class OvsBrowser(BaseBrowser):
|
|||
self.location('/profil_read.php?%s' % recipient.encode(self.ENCODING)) # FIXME
|
||||
assert self.is_on_page(PageUserProfile)
|
||||
self.page.create_thread(recipient, subject, body)
|
||||
|
||||
def get_french_cities(self):
|
||||
self.location('http://www.onvasortir.com')
|
||||
assert self.is_on_page(PageCityList)
|
||||
return self.page.get_cities('onvasortir.com')
|
||||
|
||||
def get_world_cities(self):
|
||||
self.location('http://www.urbeez.com')
|
||||
assert self.is_on_page(PageCityList)
|
||||
return self.page.get_cities('urbeez.com')
|
||||
|
||||
|
|
|
|||
|
|
@ -21,12 +21,13 @@
|
|||
import datetime
|
||||
import re
|
||||
import urllib
|
||||
from urlparse import urlsplit
|
||||
from weboob.tools.browser import BasePage
|
||||
from weboob.capabilities.messages import Message, Thread
|
||||
|
||||
import ovsparse
|
||||
|
||||
__all__ = ['PagePrivateThreadsList', 'PagePrivateThread', 'PageLogin', 'PageIndex', 'DummyPage', 'PagePostMessage', 'PageUserProfile']
|
||||
__all__ = ['PagePrivateThreadsList', 'PagePrivateThread', 'PageLogin', 'PageIndex', 'DummyPage', 'PagePostMessage', 'PageUserProfile', 'PageCityList']
|
||||
|
||||
|
||||
class OvsPage(BasePage):
|
||||
|
|
@ -172,6 +173,19 @@ class PageUserProfile(OvsPage):
|
|||
#~ self.browser.submit()
|
||||
|
||||
|
||||
class PageCityList(DummyPage):
|
||||
def get_cities(self, master_domain='onvasortir.com'):
|
||||
cities = {}
|
||||
for home_a in self.document.findAll('a', href=re.compile(r'http://(.*)\.%s/?' % master_domain)):
|
||||
hostname = urlsplit(home_a['href']).hostname
|
||||
code = hostname.split('.')[0]
|
||||
if code == 'www':
|
||||
continue
|
||||
name = home_a.text
|
||||
cities[name] = {'code': code, 'hostname': hostname}
|
||||
return cities
|
||||
|
||||
|
||||
def recode_dict(dict_, encoding):
|
||||
for k in dict_:
|
||||
dict_[k] = dict_[k].encode(encoding)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue