# selenium-energy-bot_v2018

The project contains a selenium bot which was created to automate the Energy Air or Energy Star Night competition. It is only intended as a POC and not to be used to win real tickets. (If you want to win tickets with it, you do it at your own risk.)

It is written in Python3 and requires an Android app to redirect the SMS.
After successful implementation of the Smartphone app and the Python Bot, the SMS code is automatically read after the end of the session and the game starts from the beginning.

## Configuration
[Download Python 3.7.4](https://www.python.org/ftp/python/3.7.4/python-3.7.4.exe)\
After downloading the file, run it. During the installation it is important to note that the check mark under "Add Python 3.7 to PATH" is set.\
Now open CMD and navigate to the folder "selenium-energy-bot":
```
cd \path\to\your\folder\selenium-energy-bot
```
There virtualenv must be installed:
```
pip3 install virtualenv
virtualenv venv
```
or:
```
python -m .\venv
```
Afterwards:
```
venv\Scripts\activate.bat
pip install -r requirements.txt
```

### Gmail Account needed
  * Click on [Enable The GMAIL API](https://developers.google.com/gmail/api/quickstart/python) and "Download Client Config".
  * In the Gmail Inbox [mail.google.com](https://mail.google.com/) create a new "label".
  * Under Settings (top right), go to "Filters & blocked addresses "Create new filter".
  * As subject: *Forward SMS message from number [+41YOURNR] (sender - Energy (No contact specified))*
  * Contains the words: *Dein Code für game.energy.ch*
  * Create a filter and apply it to the newly created label.
  
### Download APP PlayStore
* Download App [SMS to mail/phone - auto redirect](https://play.google.com/store/apps/details?id=com.gawk.smsforwarder)
* Configure the app to forward the SMS to your previously configured Gmail.
* Attention: The app must remain open in the background, so do not delete the app from the "open apps". Possibly adjust the energy plan on your mobile phone.

### App Iphone (optional)
* If you don't have an Android, you can also use a corresponding app from the Appstore, which redirects SMS to Mail. The regex to find the code in the string has to be adjusted in the gmail_nrg_code.py script.\
Possible App: [mysms mirror: Forward SMS](https://apps.apple.com/ch/app/mysms-mirror-sms-weiterleiten/id681057282)

### Other Downloads (REQUIRED)
* Download the [Chrome Webdriver](https://chromedriver.chromium.org/downloads) in the appropriate version for your browser.\
Find out the Webdriver version:
1. open Chrome Browser
2. click on the three points in the upper right corner
3. help, then "about Google Chrome"
4. at the top you will see "Version 78.0.3904.97"
* Alternatively you can also use webdriver of Edge or IE. But I personally had the best experiences with Chrome (adjust the webdriver in the script nggame_2019.py if you want to change it).

## Usage
### Unique execution
* Place credentials.json (GMAIL Api Auth) and chromedriver.exe in the project folder.
* In gmail_nrg_code.py there is a place (marked with Uncomment). Comment this block (Attention: After the "#" there is still a space, delete it).
* Comment the function (main()) at the last place in the code and execute the script.
```
python gmail_nrg_code.py
```
* Copy the id of the label and paste it at the following code position:
* ```results = service.users().messages().list(userId='me', labelIds=['UNREAD', 'Label_YOURIDHERE'],```
* Comment code out again. Also the function at the end!

### Execute
```python energy-bot.py```