Skip to content

Commit

Permalink
Fix database error
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayan-Bandyopadhyay committed Oct 16, 2024
1 parent 6321792 commit 28c5cb2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
18 changes: 10 additions & 8 deletions python_library/finic_py/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ def deploy():
print("Agent deployment failed")

def record(url, api_key):
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
context.tracing.start(screenshots=True, snapshots=True, sources=True)
page = browser.new_page()
page.goto(url)
# Listen for when the context is closed and save the trace
context.on("close", lambda: context.tracing.stop(path="trace.zip"))
current_dir = os.path.dirname(os.path.abspath(__file__))
subprocess.run(["playwright", "codegen", url, "--save-trace=" + current_dir + "/codegen_trace.zip"])

print("Uploading trace...")

finic = Finic(api_key=api_key)
finic.upload_trace(current_dir + "/codegen_trace.zip")

# Delete the trace file
os.remove(current_dir + "/codegen_trace.zip")
print("Trace uploaded successfully")

def main():
parser = argparse.ArgumentParser(description="CLI for Finic's python library.")
Expand Down
12 changes: 12 additions & 0 deletions python_library/finic_py/finic.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,16 @@ def deploy_agent(self, agent_id: str, agent_name: str, num_retries: int, zip_fil
response.raise_for_status()
return True

def upload_trace(self, trace_file: str) -> bool:
with open(trace_file, 'rb') as f:
upload_file = f.read()
response = requests.get(
f"{self.finic_url}/trace-upload-link",
headers={"Authorization": f"Bearer {self.api_key}"},
)
response.raise_for_status()
upload_url = response.json()["upload_url"]
response = requests.put(upload_url, data=upload_file)
response.raise_for_status()
return True

3 changes: 2 additions & 1 deletion python_library/finic_py/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ def record(url, api_key):
record("https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=ALL&media_type=all&search_type=page&view_all_page_id=108521893501", "")


# playwright codegen "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=ALL&media_type=all&search_type=page&view_all_page_id=108521893501" --save-trace=codegen_trace.zip
# playwright codegen "https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=ALL&media_type=all&search_type=page&view_all_page_id=108521893501" --save-trace=codegen_trace.zip

0 comments on commit 28c5cb2

Please sign in to comment.