-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEATURE]: Publish monthly a plot on Twitter with the gas price variation #9 #11
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
97851ed
Initial solution
Dntfreitas 1689c71
Update README
Dntfreitas 97ee826
Integration with main script
Dntfreitas 8806e41
Implementatiton of GH Action
Dntfreitas f0fef25
GH Action on the first day of the month
Dntfreitas 12720e1
Change name of the GH Action
Dntfreitas 0c6ee35
Considers only data from the last 6 months
Dntfreitas 1f4854a
Update constants.py
Dntfreitas b6e69ae
Fix issue
Dntfreitas 3267fe8
chore: typo on var
carlosrsabreu 8d9bacc
Remove nonessential comments
Dntfreitas dd6abab
Merge branch 'main' into feat/plot
Dntfreitas 9899a3e
Update constants.py
Dntfreitas d571b58
Now it generates the plot just before tweeting
Dntfreitas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Publish history plot | ||
on: | ||
schedule: | ||
- cron: "0 0 1 * *" | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checks out the repository | ||
uses: actions/checkout@v2 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Setup Python | ||
uses: actions/setup-python@v3.1.2 | ||
- name: Install project requirements | ||
run: pip install -r requirements.txt | ||
- name: Post history plot | ||
env: | ||
CONSUMER_KEY: ${{ secrets.CONSUMER_KEY }} | ||
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }} | ||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} | ||
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }} | ||
run: python script_post_plot_history.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
requests~=2.27.1 | ||
beautifulsoup4~=4.10.0 | ||
tweepy~=4.8.0 | ||
PyPDF2~=2.9.0 | ||
PyPDF2~=2.9.0 | ||
matplotlib~=3.5.3 | ||
pandas~=1.4.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -31,7 +31,7 @@ | |||||||
i = 1 | ||||||||
while i < len(gas_info): | ||||||||
if gas_info[i].startswith(NEW_DATE_KEY): | ||||||||
date_positions.append(i+1) | ||||||||
date_positions.append(i + 1) | ||||||||
i += 1 | ||||||||
|
||||||||
# Parse the last available date | ||||||||
|
@@ -49,8 +49,7 @@ | |||||||
# If we don't have the date, update | ||||||||
if update: | ||||||||
# Prepare the dictionaire | ||||||||
dict_prices = {PREVIOUS_WEEK: curret_data[CURRENT_WEEK]} | ||||||||
dict_prices[CURRENT_WEEK] = {START_DATE_KEY: start_date, END_DATE_KEY: end_date, GAS_KEY: {}} | ||||||||
dict_prices = {PREVIOUS_WEEK: curret_data[CURRENT_WEEK], CURRENT_WEEK: {START_DATE_KEY: start_date, END_DATE_KEY: end_date, GAS_KEY: {}}} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is typo Lines 13 to 15 in 010431a
|
||||||||
# Parse the data | ||||||||
i += 1 | ||||||||
while i < len(gas_info) - 1: | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import locale | ||
import tempfile | ||
|
||
import matplotlib.pyplot as plt | ||
import matplotlib.ticker as mtick | ||
import pandas as pd | ||
|
||
from constants import TWEET_HISTORY, CURRENT_GAS_HISTORY_CSV_FILE, COLUMN_START_DATE, COLUMN_GASOLINA_IO95, COLUMN_GASOLINA_IO98, COLUMN_GASOLEO_RODOVIARIO, HISTORY_PLOT_LABEL_GASOLINA_IO95, HISTORY_PLOT_LABEL_GASOLINA_IO98, HISTORY_PLOT_LABEL_GASOLEO_RODOVIARIO, HISTORY_PLOT_Y_LABEL, HISTORY_PLOT_X_LABEL | ||
from post_tweet import post_image | ||
|
||
locale.setlocale(locale.LC_ALL, 'pt_PT.UTF-8') | ||
|
||
|
||
def generate_plot_history(plot_path): | ||
# Select the last 6 months of data | ||
history = pd.read_csv(CURRENT_GAS_HISTORY_CSV_FILE) | ||
history[COLUMN_START_DATE] = pd.to_datetime(history[COLUMN_START_DATE]) | ||
history.set_index(COLUMN_START_DATE, inplace=True) | ||
history = history.last('6M').copy() | ||
|
||
# Get start and end dates | ||
start_date, end_date = history.index.min(), history.index.max() | ||
|
||
# Generate plot | ||
plt.figure() | ||
plot = history.plot(y=[COLUMN_GASOLINA_IO95, COLUMN_GASOLINA_IO98, COLUMN_GASOLEO_RODOVIARIO], | ||
label=[HISTORY_PLOT_LABEL_GASOLINA_IO95, HISTORY_PLOT_LABEL_GASOLINA_IO98, HISTORY_PLOT_LABEL_GASOLEO_RODOVIARIO], ylabel=HISTORY_PLOT_Y_LABEL, xlabel=HISTORY_PLOT_X_LABEL) | ||
|
||
plot.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.3f')) | ||
|
||
# Save plot | ||
plt.savefig(plot_path, dpi=300, bbox_inches='tight') | ||
|
||
return start_date, end_date, plot | ||
|
||
|
||
# Generate history plot | ||
temp_dir = tempfile.TemporaryDirectory() | ||
plot_path = temp_dir.name + '/plot.png' | ||
start_date, end_date, plot = generate_plot_history(plot_path) | ||
|
||
# Post tweet with image | ||
post_image(TWEET_HISTORY.format(start_date=start_date, end_date=end_date), plot_path) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line should be removed since you are not writing the file on the repo any more.