Skip to content

code I've done for a software engineer course in Genesis company

Notifications You must be signed in to change notification settings

Arniiiii/Genesis_ac_python_2022_08-2022_10

Repository files navigation

for_course

What this do?

The program do next stuff:

  1. Connects to binance websockets using binance-connector python library, it gets best ask price and best bid price for 'BTC/UAH', gets arithmetic average.
  2. Creates a server API at port 8000 which can do what's written here
    1. it can send rate, mentioned above
    2. send to emails this rate using Gmail API
    3. add emails, to which it should be sent.

How to run this?

  1. Install python3 , desirable versions are 3.10.x or 3.9.x . Depending on your system:

    1. Windows, find installer or install scoop, then scoop install python .
    2. Linux, check is it exist in repositories of your distributive
    3. MacOs, idk google it. Maybe in brew ?
    4. Android? Termux is your best friend.
  2. git clone https://github.com/Gerodote/for_course.git . If you haven't, install git. Again, in which way to do so depends on what's your system is

  3. python -mpip install --upgrade pip . Depending on your system, the beginning of the command can be python3

  4. pip install -r requirements.txt or try pip install aiofiles binance-connector fastapi uvicorn google-auth-httplib2 google-auth-oauthlib google-api-python-client python-multipart. If your CPU has ARM architecture, strongly recommend type pip install wheel before this command. Especially, if you run in termux

  5. Setup gmail account as in guide below.

  6. Run HTTP API server: uvicorn main:API --host 0.0.0.0 --port 80

  7. Check how it works with localhost:80/docs

Is docker available?

Quick answer: No

Long answer: python environment using dockerfile is appropriate, though idk how to allow gmail service server, which should work at 8080, get connection from outside to this. If you want, try:

  1. git clone https://github.com/Gerodote/for_course.git
  2. Go to folder in which this project cd ./for_course
  3. Get client_secret.json from guide below and copy it to the project folder.
  4. Build image: docker build -t for_cousre_docker_image .
  5. Try this... :docker run -it -v /project/folder/on/your/computer:/app/src -p 8000:8000 -p 8080:8080 -p 443:443 -p 80:80 -p 5353:5353 --name my-api for_cousre_docker_image
  6. Try get gmail token as in guide below (step 10 like)
  7. ???
  8. The app inside docker didn't get the token.

If you know how to resolv it, I would be pleased if you could submit an issue about this and explain how to deal with it.

How to setup a gmail account to send emails?

Main idea:

  1. Get OAuth2 key ( aka client_secret.json ) from Google Cloud Console
  2. Initialize gmail service by running either uvicorn main:API, or python mail_handler.py for getting appropriate token with appropriate permissions for using the gmail.
  3. If you don't delete the token_gmail_v1.pickle, you can run this app again without asking giving permission for sending emails from email you chose (in guide below it's step 10). (at least during one hour)

Let's start:

  1. Create a Google account. For instance, you could do this here. In this guide, I had to setup dejfwy@gmail.com.
  2. Go to console.cloud.google.com
  3. Create a project:

image image

  1. Create an OAuth app:

image image image image image image image image

  1. Enable Gmail API:

image image image

  1. Add appropriate scope (aka permissions) for your OAuth app:

image image image image image image image image

  1. Create OAuth2 credentials for getting client_secret.json

image image image image

  1. Copy the file you got to the project folder and rename it to "client_secret.json".
  2. Launch mail_handler.py or just run server: python ./mail_handler.py or uvicorn main:API
  3. Either automatically your browser shall be opened, or open the link you shall get in console. Then allow it to work:

image image image image image

  1. If you need, try to re-run mail_handler.py or server.

About

code I've done for a software engineer course in Genesis company

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published