Path.exists
Path.exists(...)Description
Documentation for Path.exists.
Real-World Examples
Practical code examples showing how Path.exists is used in real projects.
name = project["full_name"]
url = project["html_url"]
default_branch = project["default_branch"]
output_filename = re.sub(r"[^a-zA-Z0-9]+", "_", name) + ".zip"
output_path = os.path.join(self.download_dir, output_filename)
if os.path.exists(output_path):
return output_filename
time.sleep(60)
rs = requests.get(f"{url}/archive/{default_branch}.zip", stream=True)
rs.raise_for_status()
with open(output_path, "wb") as fd:
for chunk in rs.iter_content(chunk_size=8192):
fd.write(chunk)
return output_filename
def download(self):
metadata_path = os.path.join(self.download_dir, 'metadata.json')
if os.path.exists(metadata_path):
return
os.path.exists(self.download_dir) or os.mkdir(self.download_dir)
projects = list(self.github_search())
metadata = dict()
for i, project in enumerate(projects):
log.info(f"Downloading {project['full_name']} ({i + 1} of {len(projects)})")
if not date:
date = datetime.now().strftime("%Y-%m-%d")
data_file = RESEARCH_DIR / f"collected_{date}.json"
if not data_file.exists():
return {"error": f"No data found for {date}"}
try:
with open(data_file) as f:
return json.load(f)
except Exception as e:
return {"error": str(e)}
async def save_research_report(report: str, date: str | None = None) -> dict[str, Any]:
"""Save a research report.
Args:
report: The report content (markdown)
date: Date in YYYY-MM-DD format (default: today)
"""
if not date:
date = datetime.now().strftime("%Y-%m-%d")