Skip to content
This repository was archived by the owner on Jun 16, 2023. It is now read-only.

Commit f436717

Browse files
committed
docs(refactoring): Some black code refactoring
1 parent 653ff4b commit f436717

File tree

5 files changed

+26
-17
lines changed

5 files changed

+26
-17
lines changed

PyWars/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(
6060
work_dir: Union[str, Path] = "./.fchatwars",
6161
loop: asyncio.AbstractEventLoop = None,
6262
debug: bool = False,
63-
loglevel: Union[str, int] = "warning"
63+
loglevel: Union[str, int] = "warning",
6464
) -> None:
6565

6666
self._loop = loop if loop is not None else asyncio.get_event_loop()
@@ -77,7 +77,6 @@ def __init__(
7777
self._workdir = Path(work_dir)
7878
self._workdir.mkdir(exist_ok=True)
7979

80-
8180
# The properties are straigth forward so ... no explanations are needed
8281

8382
@property
@@ -93,11 +92,11 @@ def version(self) -> "Client.Version":
9392
return self._version
9493

9594
@property
96-
def debug(self)->bool:
95+
def debug(self) -> bool:
9796
return self._debug
9897

9998
@property
100-
def loglevel(self)->Union[str, int]:
99+
def loglevel(self) -> Union[str, int]:
101100
return self._logleve
102101

103102
# This is a faust topic builder with some cache (*just for internal use*)
@@ -120,7 +119,6 @@ def timer(self, seconds):
120119
@cached_property
121120
def _driven_functions(self) -> Tuple[Callable, Callable]:
122121

123-
124122
worker = Worker(
125123
self._app,
126124
loop=self.loop,
@@ -129,12 +127,14 @@ def _driven_functions(self) -> Tuple[Callable, Callable]:
129127
workdir=self.workdir,
130128
quiet=True,
131129
redirect_stdouts=False,
132-
) # We remove or preset not important setting when we create the worker
130+
) # We remove or preset not important setting when we create the worker
133131

134-
135132
worker.spinner = None # Removing anoying spinner
136133

137-
return lambda : self.loop.run_until_complete(worker.start()), worker.stop_and_shutdown
134+
return (
135+
lambda: self.loop.run_until_complete(worker.start()),
136+
worker.stop_and_shutdown,
137+
)
138138

139139
# This method starts the app execution loop
140140
def start(self):

PyWars/types/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
YellowPage,
1717
AuctionDeal,
1818
AuctionDigest,
19-
Specialization
19+
Specialization,
2020
)

examples/printing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
# We define an agent to process deals
1010

11+
1112
@app.agent(Deal) # this decorator define wath kind of topic we are specting for consume
12-
async def deals(stream: Stream[Deal]): # as we consume 'deals' topic we recieve a stream of deals
13+
async def deals(
14+
stream: Stream[Deal],
15+
): # as we consume 'deals' topic we recieve a stream of deals
1316
async for deal in stream: # we itterate over the deals
1417
print(deal) # and we print every one of them
1518

examples/telegram.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# # Example of how use it with Pyrogram
22

33
# We start importing pyrogram client and our PyWars stuff
4-
from pyrogram import Client as Telegram
4+
from pyrogram import Client as Telegram
55
from PyWars import *
66

77
# We create a telegram and a chat wars client
8-
telegram = Telegram("my_account")
9-
chat_wars = Client(loglevel='info', )
8+
telegram = Telegram("my_account")
9+
chat_wars = Client(
10+
loglevel="info",
11+
)
1012

1113
# A bucket of deals
1214
bucket = {}
@@ -15,17 +17,20 @@
1517
@chat_wars.agent(Deal)
1618
async def bucket_builder(stream: Stream[Deal]):
1719
async for deal in stream:
18-
msg = f"{deal.buyerName} buy {deal.qty} from {deal.sellerName} a {deal.price} $"
20+
msg = (
21+
f"{deal.buyerName} buy {deal.qty} from {deal.sellerName} a {deal.price} $"
22+
)
1923
if deal.item in bucket:
2024
bucket[deal.item].append(msg)
2125
else:
2226
bucket[deal.item] = [msg]
2327

28+
2429
# And a timer for post the bucket every 10 seconds
2530
@chat_wars.timer(10)
2631
async def post_deals():
2732
me = await telegram.get_me()
28-
# And late we build a post for that bucket
33+
# And late we build a post for that bucket
2934
post = ""
3035
for item, lines in bucket.items():
3136
post += f"{item}:\n\n"
@@ -35,5 +40,6 @@ async def post_deals():
3540
await telegram.send_message(me.id, post)
3641
bucket.clear()
3742

43+
3844
telegram.start()
39-
chat_wars.run()
45+
chat_wars.run()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "PyWars"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "Public topic consumer for Chat Wars API"
55
authors = ["Jesús Enrique <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)