-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from NewWays-TechForImpactKAIST/feat-scraping-…
…advance scraping 스크립트 고도화
- Loading branch information
Showing
11 changed files
with
373 additions
and
98 deletions.
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 |
---|---|---|
|
@@ -222,4 +222,5 @@ pyrightconfig.json | |
|
||
/_data | ||
/output | ||
__pycache__ | ||
__pycache__ | ||
/logs |
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 |
---|---|---|
|
@@ -12,4 +12,5 @@ gspread==5.11.2 | |
pymongo==4.5.0 | ||
python-dotenv==1.0.0 | ||
openpyxl | ||
selenium | ||
selenium | ||
tqdm |
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
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,39 @@ | ||
import os | ||
import json | ||
from dataclasses import asdict | ||
|
||
from scrap.utils.types import ScrapResult, ScrapBasicArgument | ||
|
||
|
||
def export_results_to_json( | ||
results: dict[int, ScrapResult], output_path: str, current_time: str | ||
): | ||
os.makedirs(output_path, exist_ok=True) | ||
results = { | ||
k: [asdict(councilor) for councilor in v.councilors] for k, v in results.items() | ||
} | ||
|
||
with open( | ||
os.path.join(output_path, f"scraping_result_{current_time}.json"), | ||
"w", | ||
encoding="utf-8", | ||
) as f: | ||
json.dump(results, f, ensure_ascii=False, indent=4) | ||
|
||
|
||
def export_results_to_txt( | ||
results: dict[int, ScrapResult], output_path: str, current_time: str | ||
): | ||
os.makedirs(output_path, exist_ok=True) | ||
results = { | ||
k: [asdict(councilor) for councilor in v.councilors] for k, v in results.items() | ||
} | ||
|
||
with open( | ||
os.path.join(output_path, f"scraping_result_{current_time}.txt"), | ||
"w", | ||
encoding="utf-8", | ||
) as f: | ||
for cid, councilors in results.items(): | ||
councilors = "\n".join([c.to_txt() for c in councilors]) | ||
f.write(f"| {cid} | {councilors}\n") |
Oops, something went wrong.