Skip to content

Commit

Permalink
Use ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akhmetov committed Jun 22, 2024
1 parent 806905d commit 26c2c34
Show file tree
Hide file tree
Showing 26 changed files with 558 additions and 552 deletions.
12 changes: 0 additions & 12 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@ updates:
assignees:
- alexander-akhmetov
ignore:
- dependency-name: pylint
versions:
- 2.7.0
- 2.7.3
- 2.7.4
- 2.8.1
- dependency-name: black
versions:
- 21.4b0
- dependency-name: flake8
versions:
- 3.9.0
- dependency-name: ipdb
versions:
- 0.13.5
Expand Down
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ Try to include steps to reproduce the bug, a detailed description, and some samp

## Coding style

The project uses [black](https://github.com/psf/black) as an autoformatter
and checker, along with a few linters.
The project uses [ruff](https://docs.astral.sh/ruff/) as an autoformatter and linter.

## Tests

Expand Down
93 changes: 49 additions & 44 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,22 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))

sys.path.insert(0, os.path.abspath("../.."))


# -- Project information -----------------------------------------------------

project = 'python-telegram'
copyright = '2018, Alexander Akhmetov'
author = 'Alexander Akhmetov'
project = "python-telegram"
copyright = "2018, Alexander Akhmetov"
author = "Alexander Akhmetov"

html_show_sourcelink = False

# The short X.Y version
version = ''
version = ""
# The full version, including alpha/beta/rc tags
release = ''
release = ""


# -- General configuration ---------------------------------------------------
Expand All @@ -41,20 +42,20 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
"sphinx.ext.autodoc",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -69,40 +70,40 @@
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme = "alabaster"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'logo_name': '123',
'github_user': 'alexander-akhmetov',
'github_repo': 'python-telegram',
'github_button': True,
'github_type': 'star',
'extra_nav_links': {
'Main page': '/',
'1': '',
'GitHub': 'https://github.com/alexander-akhmetov/python-telegram',
'DockerHub': 'https://hub.docker.com/r/akhmetov/python-telegram/',
'PyPi': 'https://pypi.org/project/python-telegram/',
'2': '',
}
"logo_name": "123",
"github_user": "alexander-akhmetov",
"github_repo": "python-telegram",
"github_button": True,
"github_type": "star",
"extra_nav_links": {
"Main page": "/",
"1": "",
"GitHub": "https://github.com/alexander-akhmetov/python-telegram",
"DockerHub": "https://hub.docker.com/r/akhmetov/python-telegram/",
"PyPi": "https://pypi.org/project/python-telegram/",
"2": "",
},
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -113,19 +114,18 @@
# 'searchbox.html']``.
#
html_sidebars = {
'**': [
'about.html',
'navigation.html',
'searchbox.html',
"**": [
"about.html",
"navigation.html",
"searchbox.html",
]
}



# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'python-telegramdoc'
htmlhelp_basename = "python-telegramdoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -134,15 +134,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -152,19 +149,21 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'python-telegram.tex', 'python-telegram Documentation',
'Alexander Akhmetov', 'manual'),
(
master_doc,
"python-telegram.tex",
"python-telegram Documentation",
"Alexander Akhmetov",
"manual",
),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'python-telegram', 'python-telegram Documentation',
[author], 1)
]
man_pages = [(master_doc, "python-telegram", "python-telegram Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------
Expand All @@ -173,9 +172,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'python-telegram', 'python-telegram Documentation',
author, 'python-telegram', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"python-telegram",
"python-telegram Documentation",
author,
"python-telegram",
"One line description of project.",
"Miscellaneous",
),
]


Expand Down
10 changes: 5 additions & 5 deletions examples/bot_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def bot_get_me(api_id, api_hash, token):
api_id=api_id,
api_hash=api_hash,
bot_token=token,
database_encryption_key='changeme1234',
database_encryption_key="changeme1234",
)
# you must call login method before others
tg.login()
Expand All @@ -19,10 +19,10 @@ def bot_get_me(api_id, api_hash, token):
tg.stop()


if __name__ == '__main__':
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('api_id', help='API id') # https://my.telegram.org/apps
parser.add_argument('api_hash', help='API hash')
parser.add_argument('token', help='Bot token')
parser.add_argument("api_id", help="API id") # https://my.telegram.org/apps
parser.add_argument("api_hash", help="API hash")
parser.add_argument("token", help="Bot token")
args = parser.parse_args()
bot_get_me(args.api_id, args.api_hash, args.token)
34 changes: 17 additions & 17 deletions examples/chat_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,50 @@ def retreive_messages(telegram, chat_id, receive_limit):
)
response.wait()

for message in response.update['messages']:
if message['content']['@type'] == 'messageText':
stats_data[message['id']] = message['content']['text']['text']
from_message_id = message['id']
for message in response.update["messages"]:
if message["content"]["@type"] == "messageText":
stats_data[message["id"]] = message["content"]["text"]["text"]
from_message_id = message["id"]

total_messages = len(stats_data)
if total_messages > receive_limit or not response.update['total_count']:
if total_messages > receive_limit or not response.update["total_count"]:
receive = False

print(f'[{total_messages}/{receive_limit}] received')
print(f"[{total_messages}/{receive_limit}] received")

return stats_data


def print_stats(stats_data, most_common_count):
words = Counter()
translator = str.maketrans('', '', string.punctuation)
translator = str.maketrans("", "", string.punctuation)
for _, message in stats_data.items():
for word in message.split(' '):
for word in message.split(" "):
word = word.translate(translator).lower()
if len(word) > 3:
words[word] += 1

for word, count in words.most_common(most_common_count):
print(f'{word}: {count}')
print(f"{word}: {count}")


if __name__ == '__main__':
if __name__ == "__main__":
setup_logging(level=logging.INFO)

parser = argparse.ArgumentParser()
parser.add_argument('api_id', help='API id') # https://my.telegram.org/apps
parser.add_argument('api_hash', help='API hash')
parser.add_argument('phone', help='Phone')
parser.add_argument('chat_id', help='Chat ID')
parser.add_argument('--limit', help='Messages to retrieve', type=int, default=1000)
parser.add_argument('--most-common', help='Most common count', type=int, default=30)
parser.add_argument("api_id", help="API id") # https://my.telegram.org/apps
parser.add_argument("api_hash", help="API hash")
parser.add_argument("phone", help="Phone")
parser.add_argument("chat_id", help="Chat ID")
parser.add_argument("--limit", help="Messages to retrieve", type=int, default=1000)
parser.add_argument("--most-common", help="Most common count", type=int, default=30)
args = parser.parse_args()

tg = Telegram(
api_id=args.api_id,
api_hash=args.api_hash,
phone=args.phone,
database_encryption_key='changeme1234',
database_encryption_key="changeme1234",
)
# you must call login method before others
tg.login()
Expand Down
Loading

0 comments on commit 26c2c34

Please sign in to comment.