Skip to content

Commit bbe6fbb

Browse files
author
BlackSnowDot
authored
Fix saving output
1 parent 007890a commit bbe6fbb

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

generator.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ async def run(self):
7474
async def generate(self, url: str, selector: str) -> None:
7575
while True:
7676
with suppress(Exception):
77-
session = aiohttp.ClientSession()
78-
request = await session.post(choice(url), data={"gen": ""}, timeout=self.config["request-timeout"] or 5)
79-
await session.close()
80-
outUrl = \
81-
findall("http://.*", str(BeautifulSoup(await request.text(), "html.parser").select(selector)))[0]
82-
await aprint(await self.make_beautiful(outUrl))
83-
self.output.write("%s\n" % outUrl)
77+
with open(self.config["output"], "a+") as file:
78+
session = aiohttp.ClientSession()
79+
request = await session.post(choice(url), data={"gen": ""}, timeout=self.config["request-timeout"] or 5)
80+
await session.close()
81+
outUrl = \
82+
findall("http://.*", str(BeautifulSoup(await request.text(), "html.parser").select(selector)))[0]
83+
await aprint(await self.make_beautiful(outUrl))
84+
file.write("%s" % outUrl)
8485

8586

8687
if __name__ == '__main__':

0 commit comments

Comments
 (0)