Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Frasunek committed Aug 10, 2023
0 parents commit 4fda75f
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
NETFLIX_LOGIN=yourNetflixLoginEmail
NETFLIX_PASSWORD=yourNetflixLoginPassword
EMAIL_IMAP=your.imap.server
EMAIL_LOGIN=yourEmail
EMAIL_PASSWORD=yourEmailPassword
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/
.env
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use the official Python image as the base image
FROM python:3.9

# Set the working directory inside the container
WORKDIR /app

# Copy the requirements file and install dependencies
COPY app/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code
COPY app/ .

# Define the command to run the application
CMD ["python", "main.py"]
22 changes: 22 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Netflix watcher

Update Netflix Household without interaction.

## Table of Contents

- [Project Description](#project-description)
- [Installation](#installation)

## Project Description

This is made for all the Netflix users that switches between TV's and have to update Netflix Household everytime they want to watch by confirming either via SMS or E-mail. This code checks for incoming e-mail from Netflix when you click on validate via e-mail on your TV, reads the mail, click the button, opens the page in Selenium, logs into your Netflix account and confirm your new TV. So everything you need to do is just click on check via e-mail on your TV and the rest is done here within seconds.

## Installation

Briefly describe how to set up and install your project. If there are any prerequisites, list them here.

1. Clone this repository: `git clone https://github.com/jakubfrasunek/netflixWatcher`
2. Navigate to the project directory: `cd netflixWatcher`.
3. Create your own `.env` file from `.example.env` file. `EMAIL_LOGIN` is the email that you have associated with Netflix account.
4. Run the containers: `docker compose up -d`.
5. Enjoy.
90 changes: 90 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import imaplib
import email
import re
import time
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import os

NETFLIX_LOGIN = os.environ['NETFLIX_LOGIN']
NETFLIX_PASSWORD = os.environ['NETFLIX_PASSWORD']
EMAIL_IMAP = os.environ['EMAIL_IMAP']
EMAIL_LOGIN = os.environ['EMAIL_LOGIN']
EMAIL_PASSWORD = os.environ['EMAIL_PASSWORD']


def extract_links(text):
url_pattern = r'https?://\S+'
urls = re.findall(url_pattern, text)
return urls


def open_link_with_selenium(link):
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Remote(
command_executor='http://netflix_watcher_selenium:4444/wd/hub',
options=options
)

driver.get(link)
time.sleep(2)
email_field = driver.find_element('name', 'userLoginId')
email_field.send_keys(NETFLIX_LOGIN)
password_field = driver.find_element('name', 'password')
password_field.send_keys(NETFLIX_PASSWORD)

password_field.send_keys(Keys.RETURN)
time.sleep(2)
try:
element = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, '[data-uia="set-primary-location-action"]'))
)

element.click()
except Exception as e:
print("Error:", e)

time.sleep(2)
driver.quit()


def fetch_last_unseen_email():
mail = imaplib.IMAP4_SSL(EMAIL_IMAP)
mail.login(EMAIL_LOGIN, EMAIL_PASSWORD)
mail.select("inbox")

status, email_ids = mail.search(None, '(UNSEEN FROM "info@account.netflix.com")')
email_ids = email_ids[0].split()

if email_ids:
email_id = email_ids[-1]
status, msg_data = mail.fetch(email_id, "(RFC822)")
msg = email.message_from_bytes(msg_data[0][1])

if msg.is_multipart():
for part in msg.walk():
content_type = part.get_content_type()
if "text/plain" in content_type:
body = part.get_payload(decode=True).decode()
links = extract_links(body)
for link in links:
if "update-primary-location" in link:
open_link_with_selenium(link)
else:
body = msg.get_payload(decode=True).decode()
links = extract_links(body)
for link in links:
if "update-primary-location" in link:
open_link_with_selenium(link)

mail.logout()


if __name__ == "__main__":
while True:
fetch_last_unseen_email()
time.sleep(20)
1 change: 1 addition & 0 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
selenium
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3.9"
services:
selenium:
container_name: netflix_watcher_selenium
image: seleniarm/standalone-chromium:latest
restart: always
depends_on:
- api
volumes:
- ./:/app
env_file:
- ./.env
ports:
- "4444:4444"

api:
build:
context: .
dockerfile: Dockerfile
container_name: netflix_watcher_api
restart: always
volumes:
- ./app:/app
env_file:
- ./.env

0 comments on commit 4fda75f

Please sign in to comment.