now update position randomly in Paris
This commit is contained in:
parent
406c27b020
commit
d2fb7787da
2 changed files with 22 additions and 7 deletions
|
|
@ -98,6 +98,9 @@ class HappnBrowser(DomainBrowser):
|
||||||
me = self.request('/api/users/me')
|
me = self.request('/api/users/me')
|
||||||
self.my_name = me['data']['name']
|
self.my_name = me['data']['name']
|
||||||
|
|
||||||
|
def load_state(self, *args, **kwargs):
|
||||||
|
return
|
||||||
|
|
||||||
def request(self, *args, **kwargs):
|
def request(self, *args, **kwargs):
|
||||||
r = self.location(*args, **kwargs)
|
r = self.location(*args, **kwargs)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
@ -120,3 +123,6 @@ class HappnBrowser(DomainBrowser):
|
||||||
|
|
||||||
def accept(self, id):
|
def accept(self, id):
|
||||||
self.request('/api/users/me/accepted/%s' % id, method='POST')
|
self.request('/api/users/me/accepted/%s' % id, method='POST')
|
||||||
|
|
||||||
|
def set_position(self, lat, lng):
|
||||||
|
self.request('/api/users/me/position', data={'latitude': lat, 'longitude': lng, 'altitude': 0.0})
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,13 @@
|
||||||
import datetime
|
import datetime
|
||||||
from dateutil.parser import parse as parse_date
|
from dateutil.parser import parse as parse_date
|
||||||
from dateutil.tz import tzlocal
|
from dateutil.tz import tzlocal
|
||||||
|
from random import randint
|
||||||
|
|
||||||
from weboob.capabilities.base import NotAvailable
|
from weboob.capabilities.base import NotAvailable
|
||||||
from weboob.capabilities.messages import CapMessages, CapMessagesPost, Thread, Message
|
from weboob.capabilities.messages import CapMessages, CapMessagesPost, Thread, Message
|
||||||
from weboob.capabilities.dating import CapDating, Optimization
|
from weboob.capabilities.dating import CapDating, Optimization
|
||||||
from weboob.capabilities.contact import CapContact, Contact, ProfileNode
|
from weboob.capabilities.contact import CapContact, Contact, ProfileNode
|
||||||
|
from weboob.exceptions import BrowserHTTPError
|
||||||
from weboob.tools.backend import Module, BackendConfig
|
from weboob.tools.backend import Module, BackendConfig
|
||||||
from weboob.tools.date import local2utc
|
from weboob.tools.date import local2utc
|
||||||
from weboob.tools.value import Value, ValueBackendPassword
|
from weboob.tools.value import Value, ValueBackendPassword
|
||||||
|
|
@ -63,24 +65,32 @@ class ProfilesWalker(Optimization):
|
||||||
def is_running(self):
|
def is_running(self):
|
||||||
return self._view_cron is not None
|
return self._view_cron is not None
|
||||||
|
|
||||||
|
INTERVALS = [(48896403, 2303976),
|
||||||
|
(48820992, 2414698)]
|
||||||
def view_profile(self):
|
def view_profile(self):
|
||||||
try:
|
try:
|
||||||
liked = self._storage.get('liked', default=[])
|
|
||||||
|
|
||||||
n = 0
|
n = 0
|
||||||
for user in self._browser.find_users():
|
for user in self._browser.find_users():
|
||||||
if user['notifier']['id'] in liked:
|
if user['notifier']['my_relation'] > 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._browser.accept(user['notifier']['id'])
|
self._browser.accept(user['notifier']['id'])
|
||||||
liked.append(user['notifier']['id'])
|
|
||||||
self._storage.set('liked', liked)
|
|
||||||
self._storage.save()
|
|
||||||
self._logger.info('Liked %s %s (%s at %s)', user['notifier']['first_name'], user['notifier']['last_name'], user['notifier']['job'], user['notifier']['workplace'])
|
self._logger.info('Liked %s %s (%s at %s)', user['notifier']['first_name'], user['notifier']['last_name'], user['notifier']['job'], user['notifier']['workplace'])
|
||||||
n += 1
|
n += 1
|
||||||
if n > 10:
|
if n > 10:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if n == 0:
|
||||||
|
self._logger.info('Updating position...')
|
||||||
|
lat = randint(self.INTERVALS[1][0], self.INTERVALS[0][0])/1000000.0
|
||||||
|
lng = randint(self.INTERVALS[0][1], self.INTERVALS[1][1])/1000000.0
|
||||||
|
try:
|
||||||
|
self._browser.set_position(lat, lng)
|
||||||
|
except BrowserHTTPError:
|
||||||
|
self._logger.warning('Unable to update position')
|
||||||
|
else:
|
||||||
|
self._logger.info('You are now here: https://www.google.com/maps/place//@%s,%s,17z', lat, lng)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if self._view_cron is not None:
|
if self._view_cron is not None:
|
||||||
self._view_cron = self._sched.schedule(60, self.view_profile)
|
self._view_cron = self._sched.schedule(60, self.view_profile)
|
||||||
|
|
@ -158,7 +168,6 @@ class HappnModule(Module, CapMessages, CapMessagesPost, CapDating, CapContact):
|
||||||
|
|
||||||
BROWSER = HappnBrowser
|
BROWSER = HappnBrowser
|
||||||
STORAGE = {'contacts': {},
|
STORAGE = {'contacts': {},
|
||||||
'liked': [],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def create_default_browser(self):
|
def create_default_browser(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue