-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
Updated & Optimized #70
Open
MrShadowDev
wants to merge
4
commits into
edoardottt:devel
Choose a base branch
from
MrShadowDev:main
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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,14 @@ | ||
# Set to true to add reviewers to pull requests | ||
addReviewers: true | ||
|
||
# A list of reviewers to be added to pull requests (GitHub user name) | ||
reviewers: | ||
- edoardottt | ||
|
||
# A list of keywords to be skipped the process that add reviewers if pull requests include it | ||
skipKeywords: | ||
- wip | ||
|
||
# A number of reviewers added to the pull request | ||
# Set 0 to add all the reviewers (default: 0) | ||
numberOfReviewers: 0 |
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 |
---|---|---|
|
@@ -56,7 +56,7 @@ def tweet_banner(message): | |
This is a standard tweet to spread info about the bot. | ||
""" | ||
tweet = str(datetime.datetime.now()) + "\n" | ||
tweet += "This is a bot at the service of @" + globals.user + ".\n" | ||
tweet += f"This is a bot at the service of @{globals.user}" + ".\n" | ||
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. Here the final |
||
tweet += "https://github.com/edoardottt/twitterbot2\n" | ||
tweet += message + "\n" | ||
return tweet | ||
|
@@ -81,15 +81,13 @@ def create_output_file(filename): | |
output file in the `twitterbot2-output` folder. | ||
""" | ||
directory = "twitterbot2-output" | ||
if not os.path.exists(directory + "/" + filename): | ||
_ = open(directory + "/" + filename, "w+") | ||
if not os.path.exists(f"{directory}/{filename}"): | ||
_ = open(f"{directory}/{filename}", "w+") | ||
elif answer := ask_confirmation(): | ||
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. What's the purpose of assigning |
||
_ = open(f"{directory}/{filename}", "w+") | ||
else: | ||
answer = ask_confirmation() | ||
if not answer: | ||
sys.exit() | ||
else: | ||
_ = open(directory + "/" + filename, "w+") | ||
return directory + "/" + filename | ||
sys.exit() | ||
return f"{directory}/{filename}" | ||
|
||
|
||
def ask_confirmation(): | ||
|
@@ -98,9 +96,7 @@ def ask_confirmation(): | |
existing output file. | ||
""" | ||
answer = str(input("The file already exists. Do you want to override? (Y/n)")) | ||
if answer.lower() == "y" or answer.lower() == "yes" or answer.lower() == "": | ||
return True | ||
return False | ||
return answer.lower() in {"y", "yes", ""} | ||
|
||
|
||
def output_csv(user): | ||
|
@@ -110,21 +106,18 @@ def output_csv(user): | |
(if ALL is inputted). | ||
""" | ||
conn = db.conn_db() | ||
if user == "ALL": | ||
values = db.all_stats(conn) | ||
else: | ||
values = db.user_stats(conn, user) | ||
values = db.all_stats(conn) if user == "ALL" else db.user_stats(conn, user) | ||
if len(values) == 0: | ||
logger.warning("There aren't data for this user.") | ||
sys.exit() | ||
else: | ||
create_output_folder() | ||
filename = create_output_file(user + ".csv") | ||
filename = create_output_file(f"{user}.csv") | ||
with open(filename, "w", newline="") as myfile: | ||
wr = csv.writer(myfile, quoting=csv.QUOTE_ALL) | ||
for elem in values: | ||
wr.writerow(elem) | ||
logger.info("All data has been written into " + filename) | ||
logger.info(f"All data has been written into {filename}") | ||
|
||
|
||
def output_json(user): | ||
|
@@ -134,20 +127,17 @@ def output_json(user): | |
(if ALL is inputted). | ||
""" | ||
conn = db.conn_db() | ||
if user == "ALL": | ||
values = db.all_stats(conn) | ||
else: | ||
values = db.user_stats(conn, user) | ||
values = db.all_stats(conn) if user == "ALL" else db.user_stats(conn, user) | ||
if len(values) == 0: | ||
logger.warning("There aren't data for this user.") | ||
sys.exit() | ||
else: | ||
create_output_folder() | ||
filename = create_output_file(user + ".json") | ||
filename = create_output_file(f"{user}.json") | ||
|
||
dict = {} | ||
for elem in values: | ||
if not elem[0] in dict.keys(): | ||
if elem[0] not in dict: | ||
dict[elem[0]] = {} | ||
dict[elem[0]][elem[1]] = { | ||
"tweets": elem[2], | ||
|
@@ -157,11 +147,11 @@ def output_json(user): | |
} | ||
with open(filename, "w") as f: | ||
json.dump(dict, f) | ||
logger.info("All data has been written into " + filename) | ||
logger.info(f"All data has been written into {filename}") | ||
|
||
|
||
def banner_html(): | ||
banner = """<html> | ||
return """<html> | ||
<head> | ||
<title>Twitterbot2 output</title> | ||
<style> | ||
|
@@ -223,18 +213,16 @@ def banner_html(): | |
<a href="https://github.com/edoardottt/twitterbot2/blob/main/LICENSE">License</a> | ||
</div> | ||
""" | ||
return banner | ||
|
||
|
||
def footer_html(): | ||
footer = """<div class="footer"> | ||
return """<div class="footer"> | ||
<p>twitterbot2 by <a href='https://github.com/edoardottt'>@edoardottt</a></p> | ||
</div> | ||
<br><br><br><br><br><br><br><br> | ||
</body> | ||
</html> | ||
""" | ||
return footer | ||
|
||
|
||
def html_table(lol): | ||
|
@@ -259,21 +247,18 @@ def output_html(user): | |
(if ALL is inputted). | ||
""" | ||
conn = db.conn_db() | ||
if user == "ALL": | ||
values = db.all_stats(conn) | ||
else: | ||
values = db.user_stats(conn, user) | ||
values = db.all_stats(conn) if user == "ALL" else db.user_stats(conn, user) | ||
if len(values) == 0: | ||
logger.warning("There aren't data for this user.") | ||
sys.exit() | ||
else: | ||
create_output_folder() | ||
filename = create_output_file(user + ".html") | ||
filename = create_output_file(f"{user}.html") | ||
with open(filename, "w") as f: | ||
f.write(banner_html()) | ||
f.write(html_table(values)) | ||
f.write(footer_html()) | ||
logger.info("All data has been written into " + filename) | ||
logger.info(f"All data has been written into {filename}") | ||
|
||
|
||
def data_json(values): | ||
|
@@ -283,7 +268,7 @@ def data_json(values): | |
""" | ||
dict = {} | ||
for elem in values: | ||
if not elem[0] in dict.keys(): | ||
if elem[0] not in dict: | ||
dict[elem[0]] = {} | ||
dict[elem[0]][elem[1]] = { | ||
"tweets": elem[2], | ||
|
Oops, something went wrong.
Oops, something went wrong.
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.
is there a specific reason to delete this comment?