mirror of
https://github.com/NanmiCoder/MediaCrawler.git
synced 2026-02-06 15:11:12 +08:00
refactor: 优化代码
This commit is contained in:
22
main.py
22
main.py
@@ -1,9 +1,9 @@
|
||||
import sys
|
||||
import asyncio
|
||||
import argparse
|
||||
import asyncio
|
||||
import sys
|
||||
|
||||
import db
|
||||
import config
|
||||
import db
|
||||
from base import proxy_account_pool
|
||||
from media_platform.douyin import DouYinCrawler
|
||||
from media_platform.xhs import XiaoHongShuCrawler
|
||||
@@ -17,14 +17,16 @@ class CrawlerFactory:
|
||||
elif platform == "dy":
|
||||
return DouYinCrawler()
|
||||
else:
|
||||
raise ValueError("Invalid Media Platform Currently only supported xhs or douyin ...")
|
||||
raise ValueError("Invalid Media Platform Currently only supported xhs or dy ...")
|
||||
|
||||
|
||||
async def main():
|
||||
# define command line params ...
|
||||
parser = argparse.ArgumentParser(description='Media crawler program.')
|
||||
parser.add_argument('--platform', type=str, help='Media platform select (xhs|dy)...', default=config.PLATFORM)
|
||||
parser.add_argument('--lt', type=str, help='Login type (qrcode | phone | cookie)', default=config.LOGIN_TYPE)
|
||||
parser.add_argument('--platform', type=str, help='Media platform select (xhs|dy)', choices=["xhs", "dy"],
|
||||
default=config.PLATFORM)
|
||||
parser.add_argument('--lt', type=str, help='Login type (qrcode | phone | cookie)',
|
||||
choices=["qrcode", "phone", "cookie"], default=config.LOGIN_TYPE)
|
||||
|
||||
# init account pool
|
||||
account_pool = proxy_account_pool.create_account_pool()
|
||||
@@ -34,9 +36,10 @@ async def main():
|
||||
await db.init_db()
|
||||
|
||||
args = parser.parse_args()
|
||||
crawler = CrawlerFactory().create_crawler(platform=args.platform)
|
||||
crawler = CrawlerFactory.create_crawler(platform=args.platform)
|
||||
crawler.init_config(
|
||||
command_args=args,
|
||||
platform=args.platform,
|
||||
login_type=args.lt,
|
||||
account_pool=account_pool
|
||||
)
|
||||
await crawler.start()
|
||||
@@ -44,6 +47,7 @@ async def main():
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
asyncio.run(main())
|
||||
# asyncio.run(main())
|
||||
asyncio.get_event_loop().run_until_complete(main())
|
||||
except KeyboardInterrupt:
|
||||
sys.exit()
|
||||
|
||||
Reference in New Issue
Block a user