├── requirements.txt ├── config.toml ├── wg_spider.py ├── LICENSE ├── README.md ├── wg_bot.py ├── .gitignore └── wg_submit.py /requirements.txt: -------------------------------------------------------------------------------- 1 | loguru==0.6.0 2 | ping3==4.0.3 3 | selenium==4.3.0 4 | toml==0.10.2 5 | beautifulsoup4==4.11.1 6 | urllib3==1.26.11 7 | lxml==4.9.1 8 | certifi==2019.11.28 -------------------------------------------------------------------------------- /config.toml: -------------------------------------------------------------------------------- 1 | username = "Your username" 2 | password = "Your password" 3 | message = "Your message" 4 | 5 | filters = [ 6 | 'https://www.wg-gesucht.de/en/wg-zimmer-und-1-zimmer-wohnungen-und-wohnungen-und-haeuser-in-Munchen.90.0+1+2+3.1.0.html?user_filter_id=7134295&ad_type=0&offer_filter=1&city_id=90&noDeact=1&dFr=1659045600&dTo=1664920800&rMax=800&sin=1&exc=2&img_only=1&ot=2114%2C2123%2C2124%2C2131%2C2132%2C2133&categories=0%2C1%2C2%2C3&rent_types=0', 7 | 'https://www.wg-gesucht.de/en/wg-zimmer-und-1-zimmer-wohnungen-und-wohnungen-und-haeuser-in-Garching-b-Munchen.400.0+1+2+3.1.0.html?user_filter_id=7134280&ad_type=0&offer_filter=1&city_id=400&noDeact=1&dFr=1659045600&dTo=1664920800&rMax=800&sin=1&exc=2&img_only=1&categories=0%2C1%2C2%2C3&rent_types=0', 8 | ] -------------------------------------------------------------------------------- /wg_spider.py: -------------------------------------------------------------------------------- 1 | from typing import List 2 | from bs4 import BeautifulSoup 3 | from lxml import etree 4 | import urllib3 5 | 6 | XPATH_OFFER_URL = '//div[contains(@id, "main_column")]//div[contains(@class, "wgg_card offer_list_item")]//h3[contains(@class, "truncate_title")]//a[contains(@href, "/en/")]/@href' 7 | 8 | 9 | class FilterSpider(): 10 | def __init__(self, urls: List[str]): 11 | self.urls = urls 12 | self.http = urllib3.PoolManager() 13 | 14 | def get_pages_content(self) -> List[str]: 15 | pages = [] 16 | 17 | for url in self.urls: 18 | res = self.http.request('GET', url) 19 | 20 | if res.status == 200: 21 | pages.append(res) 22 | return pages 23 | 24 | def get_offers(self) -> List[str]: 25 | pages = self.get_pages_content() 26 | 27 | urls = [] 28 | for page in pages: 29 | soup = BeautifulSoup(page.data, "html.parser") 30 | dom = etree.HTML(str(soup)) 31 | urls.extend(dom.xpath(XPATH_OFFER_URL)) 32 | return list(set(urls)) 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Alessandro Grassi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WG Bot 2 | This script aims to make life easier for people looking for homes in Germany. Specifically, it automates the search for houses and rooms on the wg-gesucht.de website and contacts the landlord privately. 3 | 4 | This is a deeply modified version of [immo](https://github.com/nickirk/immo). Rewritten to work with the latest versions of Python and the site itself. 5 | 6 | ## Requirements 7 | 1. `Python 3` (tested only on Python 3.10) 8 | - pip 9 | - venv 10 | 2. `chromedriver` (default location is `/usr/bin/chromedriver` setted on `wg_submit.py`) 11 | - For Ubuntu you can follow [this guide](https://skolo.online/documents/webscrapping/#install-chrome-browser-and-chromedriver-ubuntu-20-04) to install it. 12 | - After installing it, check the path with `which chromedriver`, if it does not match the default one, change it in the file `wg_submit.py` 13 | - If you want, you can change the Selenium configuration to replace Chrome with another browser. In this case, you will not need chromedriver 14 | 15 | ## Create the environment 16 | 1. Clone the repository with `git clone https://github.com/AlessandroGrassi99/wgbot.git` 17 | 2. Make sure you are in the root of the repository folder (inside the `wgbot` folder) 18 | 3. Edit `config.toml` with your data 19 | - Copy and replace the URL of [your wg-gesucht.de filters](https://www.wg-gesucht.de/en/mein-wg-gesucht-filter.html) into `config.toml` 20 | 5. Create Python virtual environment with `python -m venv venv` 21 | 6. Activate python's virtual environment with `source venv/bin/activate` 22 | 7. Install dependencies with `pip install -r requirements.txt` 23 | 24 | ## Run 25 | 1. Activate python's virtual environment with `source venv/bin/activate` 26 | 2. Run `python wg_bot.py` 27 | 28 | ## Tips and troubleshooting 29 | - Use the filters with the English version of the site, they must be in the format `https://www.wg-gesucht.de/en/`, with `/en/` at the end 30 | - Currently Selenium and other dependencies have some problems on macOS systems. Unfortunately, these are not problems that depend directly on the script; I recommend using a VM with Ubuntu. 31 | - I suggest you to check the README file of the [original project](https://github.com/nickirk/immo), there might be interesting insights there 32 | -------------------------------------------------------------------------------- /wg_bot.py: -------------------------------------------------------------------------------- 1 | from logging import Filter 2 | from subprocess import call 3 | from wg_submit import submit_app 4 | from wg_spider import FilterSpider 5 | import json 6 | import os.path 7 | import time 8 | import toml 9 | 10 | from loguru import logger 11 | 12 | CONFIG_NAME = "config.toml" 13 | CACHE_FNAME = "wg_cache.json" 14 | 15 | 16 | def get_data(cache_fname: str, spider: FilterSpider): 17 | new_urls = spider.get_offers() 18 | if os.path.isfile(cache_fname): 19 | with open(cache_fname) as data_file: 20 | try: 21 | old_urls = json.load(data_file) 22 | except json.JSONDecodeError as e: 23 | old_urls = [] 24 | diff_urls = list(set(new_urls) - set(old_urls)) 25 | else: 26 | logger.info(f"{len(new_urls):03d} offers found: {new_urls}") 27 | while True: 28 | input_data = input("No wg_cache.json file found. Sending messages to all offers found above? (y/n)\n").lower() 29 | if input_data == "y": 30 | diff_urls = new_urls 31 | break 32 | elif input_data == "n": 33 | diff_urls = [] 34 | break 35 | logger.warning("Invalid input") 36 | 37 | with open(cache_fname, 'w') as cache_file: 38 | cache_file.write(json.dumps(new_urls)) 39 | 40 | return diff_urls 41 | 42 | 43 | def get_config(config_name): 44 | with open(config_name) as data_file: 45 | return toml.load(data_file) 46 | 47 | 48 | def main(): 49 | config = get_config(CONFIG_NAME) 50 | spider = FilterSpider(config['filters']) 51 | logger.info("Starting service") 52 | 53 | while True: 54 | new_urls = get_data(CACHE_FNAME, spider) 55 | 56 | logger.info(f"{len(new_urls):03d} New offers found: {new_urls}") 57 | for url in new_urls: 58 | logger.info(f"Sending message to {url}...") 59 | contacted = False 60 | for _ in range(0, 3): 61 | if submit_app(config, url): 62 | contacted = True 63 | break 64 | logger.warning("Retry to contact") 65 | if contacted: 66 | logger.info("Successfully contacted") 67 | else: 68 | logger.error("Unable to contact") 69 | 70 | time.sleep(30) 71 | 72 | 73 | if __name__ == "__main__": 74 | main() 75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.toptal.com/developers/gitignore/api/python,pycharm+all,venv,visualstudiocode 2 | # Edit at https://www.toptal.com/developers/gitignore?templates=python,pycharm+all,venv,visualstudiocode 3 | 4 | selenium/ 5 | wg_cache.json 6 | 7 | ### PyCharm+all ### 8 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 9 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 10 | 11 | # User-specific stuff 12 | .idea/**/workspace.xml 13 | .idea/**/tasks.xml 14 | .idea/**/usage.statistics.xml 15 | .idea/**/dictionaries 16 | .idea/**/shelf 17 | 18 | # AWS User-specific 19 | .idea/**/aws.xml 20 | 21 | # Generated files 22 | .idea/**/contentModel.xml 23 | 24 | # Sensitive or high-churn files 25 | .idea/**/dataSources/ 26 | .idea/**/dataSources.ids 27 | .idea/**/dataSources.local.xml 28 | .idea/**/sqlDataSources.xml 29 | .idea/**/dynamic.xml 30 | .idea/**/uiDesigner.xml 31 | .idea/**/dbnavigator.xml 32 | 33 | # Gradle 34 | .idea/**/gradle.xml 35 | .idea/**/libraries 36 | 37 | # Gradle and Maven with auto-import 38 | # When using Gradle or Maven with auto-import, you should exclude module files, 39 | # since they will be recreated, and may cause churn. Uncomment if using 40 | # auto-import. 41 | # .idea/artifacts 42 | # .idea/compiler.xml 43 | # .idea/jarRepositories.xml 44 | # .idea/modules.xml 45 | # .idea/*.iml 46 | # .idea/modules 47 | # *.iml 48 | # *.ipr 49 | 50 | # CMake 51 | cmake-build-*/ 52 | 53 | # Mongo Explorer plugin 54 | .idea/**/mongoSettings.xml 55 | 56 | # File-based project format 57 | *.iws 58 | 59 | # IntelliJ 60 | out/ 61 | 62 | # mpeltonen/sbt-idea plugin 63 | .idea_modules/ 64 | 65 | # JIRA plugin 66 | atlassian-ide-plugin.xml 67 | 68 | # Cursive Clojure plugin 69 | .idea/replstate.xml 70 | 71 | # SonarLint plugin 72 | .idea/sonarlint/ 73 | 74 | # Crashlytics plugin (for Android Studio and IntelliJ) 75 | com_crashlytics_export_strings.xml 76 | crashlytics.properties 77 | crashlytics-build.properties 78 | fabric.properties 79 | 80 | # Editor-based Rest Client 81 | .idea/httpRequests 82 | 83 | # Android studio 3.1+ serialized cache file 84 | .idea/caches/build_file_checksums.ser 85 | 86 | ### PyCharm+all Patch ### 87 | # Ignore everything but code style settings and run configurations 88 | # that are supposed to be shared within teams. 89 | 90 | .idea/* 91 | 92 | !.idea/codeStyles 93 | !.idea/runConfigurations 94 | 95 | ### Python ### 96 | # Byte-compiled / optimized / DLL files 97 | __pycache__/ 98 | *.py[cod] 99 | *$py.class 100 | 101 | # C extensions 102 | *.so 103 | 104 | # Distribution / packaging 105 | .Python 106 | build/ 107 | develop-eggs/ 108 | dist/ 109 | downloads/ 110 | eggs/ 111 | .eggs/ 112 | lib/ 113 | lib64/ 114 | parts/ 115 | sdist/ 116 | var/ 117 | wheels/ 118 | share/python-wheels/ 119 | *.egg-info/ 120 | .installed.cfg 121 | *.egg 122 | MANIFEST 123 | 124 | # PyInstaller 125 | # Usually these files are written by a python script from a template 126 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 127 | *.manifest 128 | *.spec 129 | 130 | # Installer logs 131 | pip-log.txt 132 | pip-delete-this-directory.txt 133 | 134 | # Unit test / coverage reports 135 | htmlcov/ 136 | .tox/ 137 | .nox/ 138 | .coverage 139 | .coverage.* 140 | .cache 141 | nosetests.xml 142 | coverage.xml 143 | *.cover 144 | *.py,cover 145 | .hypothesis/ 146 | .pytest_cache/ 147 | cover/ 148 | 149 | # Translations 150 | *.mo 151 | *.pot 152 | 153 | # Django stuff: 154 | *.log 155 | local_settings.py 156 | db.sqlite3 157 | db.sqlite3-journal 158 | 159 | # Flask stuff: 160 | instance/ 161 | .webassets-cache 162 | 163 | # Scrapy stuff: 164 | .scrapy 165 | 166 | # Sphinx documentation 167 | docs/_build/ 168 | 169 | # PyBuilder 170 | .pybuilder/ 171 | target/ 172 | 173 | # Jupyter Notebook 174 | .ipynb_checkpoints 175 | 176 | # IPython 177 | profile_default/ 178 | ipython_config.py 179 | 180 | # pyenv 181 | # For a library or package, you might want to ignore these files since the code is 182 | # intended to run in multiple environments; otherwise, check them in: 183 | # .python-version 184 | 185 | # pipenv 186 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 187 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 188 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 189 | # install all needed dependencies. 190 | #Pipfile.lock 191 | 192 | # poetry 193 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 194 | # This is especially recommended for binary packages to ensure reproducibility, and is more 195 | # commonly ignored for libraries. 196 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 197 | #poetry.lock 198 | 199 | # pdm 200 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 201 | #pdm.lock 202 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 203 | # in version control. 204 | # https://pdm.fming.dev/#use-with-ide 205 | .pdm.toml 206 | 207 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 208 | __pypackages__/ 209 | 210 | # Celery stuff 211 | celerybeat-schedule 212 | celerybeat.pid 213 | 214 | # SageMath parsed files 215 | *.sage.py 216 | 217 | # Environments 218 | .env 219 | .venv 220 | env/ 221 | venv/ 222 | ENV/ 223 | env.bak/ 224 | venv.bak/ 225 | 226 | # Spyder project settings 227 | .spyderproject 228 | .spyproject 229 | 230 | # Rope project settings 231 | .ropeproject 232 | 233 | # mkdocs documentation 234 | /site 235 | 236 | # mypy 237 | .mypy_cache/ 238 | .dmypy.json 239 | dmypy.json 240 | 241 | # Pyre type checker 242 | .pyre/ 243 | 244 | # pytype static type analyzer 245 | .pytype/ 246 | 247 | # Cython debug symbols 248 | cython_debug/ 249 | 250 | # PyCharm 251 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 252 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 253 | # and can be added to the global gitignore or merged into this file. For a more nuclear 254 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 255 | #.idea/ 256 | 257 | ### venv ### 258 | # Virtualenv 259 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ 260 | [Bb]in 261 | [Ii]nclude 262 | [Ll]ib 263 | [Ll]ib64 264 | [Ll]ocal 265 | [Ss]cripts 266 | pyvenv.cfg 267 | pip-selfcheck.json 268 | 269 | ### VisualStudioCode ### 270 | .vscode/* 271 | !.vscode/settings.json 272 | !.vscode/tasks.json 273 | !.vscode/launch.json 274 | !.vscode/extensions.json 275 | !.vscode/*.code-snippets 276 | 277 | # Local History for Visual Studio Code 278 | .history/ 279 | 280 | # Built Visual Studio Code Extensions 281 | *.vsix 282 | 283 | ### VisualStudioCode Patch ### 284 | # Ignore all local history of files 285 | .history 286 | .ionide 287 | 288 | # Support for Project snippet scope 289 | .vscode/*.code-snippets 290 | 291 | # Ignore code-workspaces 292 | *.code-workspace 293 | 294 | # End of https://www.toptal.com/developers/gitignore/api/python,pycharm+all,venv,visualstudiocode -------------------------------------------------------------------------------- /wg_submit.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.action_chains import ActionChains 3 | from selenium.common.exceptions import NoSuchElementException, TimeoutException, WebDriverException 4 | from selenium.webdriver.common.by import By 5 | 6 | from loguru import logger 7 | import socket 8 | import time 9 | 10 | 11 | XPATH_SEND_MESSAGE_BTN = "//div[contains(@class, 'panel')]//a[@class='btn btn-block btn-md wgg_orange'][contains(., 'Send Message')]" 12 | XPATH_VIEW_CONVERSATION_BTN = "//div[contains(@class, 'panel')]//a[@class='btn btn-md btn-block wgg_blue'][contains(., 'View conversation')]" 13 | XPATH_SUBMIT_BTN = "//form[@id='messenger_form']//button[@type='submit' and contains(.,'Send message')]" 14 | XPATH_INPUT_TXT = "//div[@id='start_new_conversation']//textarea[@id='message_input']" 15 | XPATH_COOKIES_ACCEPT = "/html/body/div[@id='cmpbox']/div[@class='cmpboxinner']/div[@class='cmpboxbtns']/span[@id='cmpwelcomebtnyes']/a[@class='cmpboxbtn cmpboxbtnyes cmptxt_btn_yes']" 16 | XPATH_LOGIN_NAV = '//*[@id="main-nav-wrapper"]/nav[1]/div[3]/div/a[@onclick="{}"]'.format("fireLoginOrRegisterModalRequest('sign_in');ga('send', 'event', 'main_navigation', 'login', '1st_level');") 17 | XPATH_LANG_BTN = "//span[@class='text-uppercase cursor-pointer dropdown-toggle footer_selected_language'][contains(., 'de')]" 18 | XPATH_LANG_ENG_BTN = "//div[@class='footer_language_selection language_wrapper mt5']//div[@class='dropup noprint display-inline open']//a[normalize-space()='English']" 19 | MAX_TRIES = 3 20 | 21 | 22 | def submit_app(config, offer) -> bool: 23 | url = 'https://www.wg-gesucht.de' + offer 24 | logger.debug("Opening the website: {url}", url=url) 25 | 26 | driver = driver_connect(url) 27 | if driver is None: 28 | logger.warning("Unable to start drivers") 29 | return False 30 | 31 | set_lang(driver) 32 | accept_cookies(driver) 33 | try_to_login(driver, config) 34 | 35 | try: 36 | send_message_buttons = driver.find_element(By.XPATH, XPATH_SEND_MESSAGE_BTN) 37 | send_message_buttons.click() 38 | logger.debug("Opening new conversation...") 39 | except NoSuchElementException as err: 40 | try: 41 | driver.find_element(By.XPATH, XPATH_VIEW_CONVERSATION_BTN) 42 | logger.debug("Already sent message to this offer, closing the browser...") 43 | driver.quit() 44 | return True 45 | except NoSuchElementException as err: 46 | logger.debug("Unable to identify the conversation with the landlord") 47 | driver.quit() 48 | return False 49 | except (TimeoutException, WebDriverException) as err: 50 | logger.exception("Unexpected driver problem") 51 | return False 52 | except (TimeoutException, WebDriverException) as err: 53 | logger.exception("Unexpected driver problem") 54 | return False 55 | 56 | close_security_advice_alert(driver) 57 | 58 | submit_button = find_submit_btn(driver) 59 | text_area = find_input_txt(driver) 60 | 61 | if not text_area and not submit_button: 62 | logger.debug("Already sent message to this offer, closing the browser...") 63 | driver.quit() 64 | return True 65 | elif not text_area or not submit_button: 66 | driver.quit() 67 | return False 68 | 69 | logger.debug("Writing message...") 70 | text_area.clear() 71 | text_area.send_keys(config['message']) 72 | logger.debug("Sending message...") 73 | submit_button.click() 74 | 75 | time.sleep(1) 76 | 77 | driver.quit() 78 | logger.debug("Sent") 79 | return True 80 | 81 | 82 | def driver_connect(url): 83 | for tries in range(0, MAX_TRIES): 84 | try: 85 | options = webdriver.ChromeOptions() 86 | options.add_argument("--window-size=1600,900") 87 | options.add_argument("user-data-dir=selenium") 88 | # options.headless = True 89 | 90 | logger.debug("Opening the browser") 91 | driver = webdriver.Chrome(chrome_options=options, executable_path='/usr/bin/chromedriver') 92 | except (TimeoutException, WebDriverException) as err: 93 | if tries + 1 == MAX_TRIES: 94 | return None 95 | if not check_connection(): 96 | time.sleep(30) 97 | logger.info("Retrying...") 98 | continue 99 | 100 | try: 101 | driver.get(url) 102 | return driver 103 | except (TimeoutException, WebDriverException) as err: 104 | if tries + 1 == MAX_TRIES: 105 | return None 106 | if not check_connection(): 107 | time.sleep(30) 108 | logger.info("Retrying...") 109 | driver.quit() 110 | 111 | return None 112 | 113 | 114 | def find_submit_btn(driver): 115 | try: 116 | return driver.find_element(By.XPATH, XPATH_SUBMIT_BTN) 117 | except NoSuchElementException: 118 | logger.debug("Cannot find 'submit' button") 119 | return None 120 | 121 | 122 | def find_input_txt(driver): 123 | try: 124 | return driver.find_element(By.XPATH, XPATH_INPUT_TXT) 125 | except NoSuchElementException: 126 | logger.debug("Cannot find 'start new conversation' textarea") 127 | driver.quit() 128 | return False 129 | 130 | 131 | def set_lang(driver): 132 | try: 133 | lang_button = driver.find_element(By.XPATH, XPATH_LANG_BTN) 134 | logger.debug("Setting lang to EN...") 135 | lang_button.click() 136 | 137 | lang_en_button = driver.find_element(By.XPATH, XPATH_LANG_ENG_BTN) 138 | lang_en_button.click() 139 | time.sleep(5) 140 | except NoSuchElementException: 141 | pass 142 | 143 | 144 | def close_security_advice_alert(driver): 145 | try: 146 | agree_button = driver.find_element(By.ID, "sicherheit_bestaetigung") 147 | logger.debug("Closing security advice alert...") 148 | agree_button.click() 149 | except NoSuchElementException: 150 | pass 151 | 152 | 153 | def accept_cookies(driver): 154 | try: 155 | accept_button = driver.find_element(By.XPATH, XPATH_COOKIES_ACCEPT) 156 | logger.debug("Closing cookies alert...") 157 | accept_button.click() 158 | except NoSuchElementException: 159 | pass 160 | 161 | 162 | def try_to_login(driver, config): 163 | try: 164 | login_dialog_button = driver.find_element(By.XPATH, XPATH_LOGIN_NAV) 165 | logger.debug("Login...") 166 | login_dialog_button.click() 167 | 168 | driver.implicitly_wait(1) 169 | email = driver.find_element(By.ID, 'login_email_username') 170 | email.send_keys(config['username']) 171 | passwd = driver.find_element(By.ID, 'login_password') 172 | passwd.send_keys(config['password']) 173 | # Enabled by default 174 | # remember_button = driver.find_element(By.ID, 'auto_login') 175 | # remember_button.click() 176 | 177 | login_button = driver.find_element(By.ID, 'login_submit') 178 | login_button.click() 179 | # TODO Check that it is logged in correctly without errors 180 | logger.debug("Logged") 181 | except: 182 | pass 183 | 184 | 185 | def check_connection(): 186 | try: 187 | hostname = "one.one.one.one" 188 | # see if we can resolve the host name -- tells us if there is 189 | # a DNS listening 190 | host = socket.gethostbyname(hostname) 191 | # connect to the host -- tells us if the host is actually reachable 192 | s = socket.create_connection((host, 80), 2) 193 | s.close() 194 | return True 195 | 196 | except Exception: 197 | return False 198 | --------------------------------------------------------------------------------