Code Monkey home page Code Monkey logo

devo-abastecer's Introduction

⛽️ Devo Abastecer (beta)

Important

⛽️ Update Gas Prices from DRETT 📈 Publish History Plot 💅 Format Codebase

🇵🇹 Informação acessível com os preços dos combustíveis na Madeira, publicada semanalmente no Twitter recorrendo a um bot.
🇬🇧 Up-to-date fuel prices in Madeira, conveniently updated weekly on Twitter via our automated bot.

Fuel price history

Gas History

Functionality Overview

This project automates the process of updating and publishing fuel prices in Madeira. The sequence summary below provides an overview of the main functionalities and interactions between components:

sequenceDiagram

    participant 🐍 joram.py
    participant 🐍 update_gas_prices.py
    participant 🐍 add_history.py
    participant 🐍 post_tweet.py

    🐍 update_gas_prices.py -->> 🐍 update_gas_prices.py: 🐍 constants.py: import constants
    🐍 update_gas_prices.py ->> 🐍 joram.py: 🆕 retrieve newest pdf gas info
    🐍 joram.py -->> 🐍 joram.py: 🌐 joram: get pdf content
    🐍 joram.py -->> 🐍 update_gas_prices.py: 🏷️ gas prices and creation date
    🐍 update_gas_prices.py -->> 🐍 update_gas_prices.py: 🐍 functions.py: retrieve week
    🐍 update_gas_prices.py -->> 🐍 update_gas_prices.py: 🐍 functions.py: replace key names
    🐍 update_gas_prices.py -->> 🐍 update_gas_prices.py: 📅 add start date, end date
    🐍 update_gas_prices.py ->> 🐍 update_gas_prices.py: 💾 update gas_info.json
    🐍 update_gas_prices.py ->> 🐍 add_history.py: 📊 add price to history
    🐍 add_history.py ->> 🐍 add_history.py: 💾 update gas_info_history.csv
    🐍 add_history.py ->> 🐍 add_history.py: 💾 update gas_info_history.json
    🐍 update_gas_prices.py ->> 🐍 post_tweet.py: 📩 make tweet
    🐍 post_tweet.py -->> 🐍 post_tweet.py: 📨 format tweet message
    🐍 post_tweet.py -->> 🐍 post_tweet.py: 📮 post tweet

devo-abastecer's People

Contributors

dntfreitas avatar harryvasanth avatar carlosrsabreu avatar dependabot[bot] avatar github-actions[bot] avatar 13dev avatar

Stargazers

Duarte Santos avatar  avatar  avatar Pedro Rodrigues avatar Roman avatar  avatar  avatar Carlos Menezes avatar Cláudio Rodrigues avatar João Freitas avatar

Watchers

 avatar  avatar  avatar Kostas Georgiou avatar

Forkers

13dev

devo-abastecer's Issues

[FEATURE]: Implement general optimizations

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

  • N/A

Describe the solution you'd like

A clear and concise description of what you want to happen.

  • Workflow to uniformly format the entire codebase, instead of relying on individual linting
  • Refactor to reflect the rest of the repository's naming convention

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

  • N/A

Additional context

Add any other context or screenshots about the feature request here.

  • Finding a simple and effective way to organize the codebase

[BUG]: Workflow fails on `main.yml`

Describe the bug

  1. Currently, the GitHub workflow main.yml is failing.
    Extract data from DRTT

  2. The file history/img/plot.png doesn't exist in the repository.

  3. However, the workflow is still referring to it and attempts to make a commit:

    git add history/img/plot.png

Expected behaviour

  • The GitHub workflow main.yml executes as usual.

To Reproduce

  • Trigger the GitHub workflow: main.yml

Additional context

  • N/A

[FEATURE]: Get PDF links that contains gas prices from JORAM

Expected Behavior

At this moment, we have a scrapper that reads a JORAM PDF file and returns a dictionary with the gas prices. You can check the scrapper in this file.

  • The PDF files can be found in this link;
  • The weekly gas prices are issued on Thursdays or Fridays (most of them on Fridays);
  • The 2.º Suplemento PDF files are the ones that contain gas prices (but not all of them).

You can check some examples here:

image

Actual Behavior

The gas prices are retrieved from the Direção Regional de Economia e Transportes Terrestres website.

However, these prices are not updated every Friday (as the JORAM document is issued with gas prices for the next week), so sometimes we can get the gas prices after the current week and don't have the info in time.

To check how we retrieve the gas prices at this moment, check this file.

[BUG]: Change JORAM ref link year from `2023` to `{date:%Y}`

Describe the issue

The constants.py currently refers to the year 2023 due to debugging reasons.

Describe the solution you'd like

As per PR #58:

  • The JORAM website published the page for the year 2024 (Link)
  • The reference for the year needs to be changed from 2023 to {date:%Y}

Additional context

# JORAM link 2023 - For Debugging
- JORAM_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%202023"
- JORAM_PDF_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%202023/{file}"
+ #JORAM_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%202023"
+ #JORAM_PDF_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%202023/{file}"

# JORAM link
- #JORAM_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%20{date:%Y}"
- #JORAM_PDF_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%20{date:%Y}/{file}"
+ JORAM_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%20{date:%Y}"
+ JORAM_PDF_LINK = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%20{date:%Y}/{file}"

[BUG]: Publish gas prices

Expected Behavior

When the file gas_info.json is changed, it should publish the tweet message.

Actual Behavior

There's a pipeline (main.yml) with a cronjob that verifies if new gas prices were released. If that happens, a commit is triggered by a pipeline. Then, there's another pipeline (create_tweet.yml) that should be triggered to run the tweet.py file. However, at this moment, this pipeline is not triggered.

[BUG]: Gas dates have a delay of one week

Describe the bug

A clear and concise description of what the bug is.

Gas dates have a delay of one week, even if the prices are the most recent ones.

Expected behaviour

A clear and concise description of what you expected to happen.

It should return the correct gas dates, considering that PDF creation date have prices for the following week.

To Reproduce

Steps to reproduce the behaviour: >

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Additional context

Add any other context about the problem here.

[BUG]: Workflow Fail – Extract data from DRTT

Expected Behavior

➡️ Run python script.py > gas_info.json

  python script.py > gas_info.json
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/[3](https://github.com/carlosrsabreu/devo-abastecer/runs/6851627521?check_suite_focus=true#step:5:3).10.[4](https://github.com/carlosrsabreu/devo-abastecer/runs/6851627521?check_suite_focus=true#step:5:4)/x[6](https://github.com/carlosrsabreu/devo-abastecer/runs/6851627521?check_suite_focus=true#step:5:6)4
    LD_LIBRARY_PATH: /opt/hostedtoolcache/Python/3.10.4/x64/lib

Actual Behavior

➡️ Run python script.py > gas_info.json

Traceback (most recent call last):
  File "/home/runner/work/devo-abastecer/devo-abastecer/script.py", line 32, in <module>
    start_date, end_date = gas_info[i].replace('.', '-').split('\xa0a ')
ValueError: not enough values to unpack (expected 2, got 1)
Error: Process completed with exit code 1.

Steps to Reproduce the Problem

Extract data from DRTT

  1. The issue currently exists in all branches.
  2. The issue can be reproduced by running the workflow manually or on schedule.

[FEATURE]: improve debug local tests

Is your feature request related to a problem? Please describe.

A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

We need to improve our local tests, so we can have our *.py files cleaned out of debug code.

Describe the solution you'd like

A clear and concise description of what you want to happen.

As suggested by the @joaoofreitas:

  • Remove Debug info and maybe create a python test file;
  • Encapsulate debug code inside a callable function for testing and re-usability.

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

N.A.

Additional context

Add any other context or screenshots about the feature request here.

# FIXME (DEBUG) Print se the filename to scrape the content
print(newest_pdf_filename)
# FIXME (DEBUG): Working link to Joram PDF
debug_pdf_joram = "https://joram.madeira.gov.pt/joram/2serie/Ano%20de%202022/IISerie-138-2022-07-22Supl.pdf"
Tip

[FEATURE]: Improve Documentation

Expected Behaviour

  • The readme reflects the repository in adequate detail
  • The issue templates supports both bugs and features/enhancements
  • The pull request template facilitates the assignee

Actual Behaviour

  • Descriptive readme
  • Boiler plate issue template
  • Boiler plate pull request template

[FEATURE]: Retrieve gas prices

Expected Behavior

The prices should be retrieved from the JORAM website. The weekly gas prices are issued every Friday, in 2.º Suplemento. You can check some examples here:

image

Actual Behavior

Right now, the gas prices are retrieved from the Direção Regional de Economia e Transportes Terrestres website. However, these prices are not updated every Friday (as the JORAM document is issued with gas prices for the next week).

To check how we retrieve the gas prices at this moment, check this file.

[FEATURE]: Use JORAM gas prices

Is your feature request related to a problem? Please describe.

A clear and concise description of the problem. Ex. I'm always frustrated when [...]

We should drop DRET gas prices (they are unstable and the format constantly changes).

Describe the solution you'd like

A clear and concise description of what you want to happen.

Use JORAM gas prices (more stable, using the same format).

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

Add any other context or screenshots about the feature request here.

[BUG]: Workflow Fail – Extract data from DRTT #2

Expected Behavior

➡️ Run python script.py

Run python script.py
  python script.py
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/[3](https://github.com/carlosrsabreu/devo-abastecer/actions/runs/3855845927/jobs/6571353639#step:5:3).11.1/x6[4](https://github.com/carlosrsabreu/devo-abastecer/actions/runs/3855845927/jobs/6571353639#step:5:4)

Actual Behavior

➡️ Run python script.py

Run python script.py
  python script.py
  shell: /usr/bin/bash -e {0}
  env:
    pythonLocation: /opt/hostedtoolcache/Python/[3](https://github.com/carlosrsabreu/devo-abastecer/actions/runs/3856013359/jobs/6571714706#step:5:3).11.1/x6[4](https://github.com/carlosrsabreu/devo-abastecer/actions/runs/3856013359/jobs/6571714706#step:5:4)

Traceback (most recent call last):
  File "/home/runner/work/devo-abastecer/devo-abastecer/script.py", line [5](https://github.com/carlosrsabreu/devo-abastecer/actions/runs/3856013359/jobs/6571714706#step:5:5)[8](https://github.com/carlosrsabreu/devo-abastecer/actions/runs/3856013359/jobs/6571714706#step:5:8), in <module>
    price = float(gas_info[i + 1][:-1].replace(',', '.'))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: 'Gasolina IO[9](https://github.com/carlosrsabreu/devo-abastecer/actions/runs/3856013359/jobs/6571714706#step:5:9)'
Error: Process completed with exit code 1.

Steps to Reproduce the Problem

Extract data from DRTT

  1. The issue currently exists in all branches.
  2. The issue can be reproduced by running the workflow manually or on schedule.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.