Technologic101 commited on
Commit
e2784d5
·
1 Parent(s): 80f27e2

task: combine notebooks

Browse files
Files changed (2) hide show
  1. notebook.ipynb +38 -6
  2. test_scraper.ipynb +0 -127
notebook.ipynb CHANGED
@@ -4,9 +4,43 @@
4
  "cell_type": "markdown",
5
  "metadata": {},
6
  "source": [
7
- "# Test CSS Zen Garden Scraper and Analyzer\n",
8
  "\n",
9
- "This notebook tests the scraper and design analyzer."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  ]
11
  },
12
  {
@@ -62,11 +96,8 @@
62
  "from pathlib import Path\n",
63
  "import asyncio\n",
64
  "\n",
65
- "# Test designs to analyze\n",
66
- "test_design_ids = [\"220\", \"221\"]\n",
67
- "\n",
68
  "async def test_analyzer():\n",
69
- " for design_id in test_design_ids:\n",
70
  " design_path = Path(f\"designs/{design_id}\")\n",
71
  " result = await analyze_screenshot(design_id, design_path)\n",
72
  " \n",
@@ -74,6 +105,7 @@
74
  " print(f\"\\nAnalysis for design {design_id}:\")\n",
75
  " print(f\"Description: {result[1]}\")\n",
76
  " print(f\"Categories: {', '.join(result[2])}\")\n",
 
77
  "\n",
78
  "await test_analyzer()"
79
  ]
 
4
  "cell_type": "markdown",
5
  "metadata": {},
6
  "source": [
7
+ "# Zen Garden Design Analysis\n",
8
  "\n",
9
+ "To collect our design data, we scrape csszengarden.com for design screenshots and associated styles. With over 200 designs, this should give us a good training set on how apply different styles and techniques."
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 1,
15
+ "metadata": {},
16
+ "outputs": [
17
+ {
18
+ "name": "stdout",
19
+ "output_type": "stream",
20
+ "text": [
21
+ "Testing scraper with design 010...\n",
22
+ "010: Response status: 200\n",
23
+ "Success!\n"
24
+ ]
25
+ }
26
+ ],
27
+ "source": [
28
+ "from scraper import scrape_design\n",
29
+ "import asyncio\n",
30
+ "\n",
31
+ "# Pick from a range of 001 to 221\n",
32
+ "#test_set = [f\"{i:03d}\" for i in range(1, 21)]\n",
33
+ "test_set = [\"010\"]\n",
34
+ "async def test_scraper(ids):\n",
35
+ " for test_design_id in ids:\n",
36
+ " try:\n",
37
+ " print(f\"Testing scraper with design {test_design_id}...\")\n",
38
+ " await scrape_design(test_design_id)\n",
39
+ " print(\"Success!\")\n",
40
+ " except Exception as e:\n",
41
+ " print(f\"Error: {str(e)}\")\n",
42
+ "\n",
43
+ "await test_scraper(test_set)"
44
  ]
45
  },
46
  {
 
96
  "from pathlib import Path\n",
97
  "import asyncio\n",
98
  "\n",
 
 
 
99
  "async def test_analyzer():\n",
100
+ " for design_id in test_set:\n",
101
  " design_path = Path(f\"designs/{design_id}\")\n",
102
  " result = await analyze_screenshot(design_id, design_path)\n",
103
  " \n",
 
105
  " print(f\"\\nAnalysis for design {design_id}:\")\n",
106
  " print(f\"Description: {result[1]}\")\n",
107
  " print(f\"Categories: {', '.join(result[2])}\")\n",
108
+ " print(f\"Visual Characteristics: {', '.join(result[3])}\")\n",
109
  "\n",
110
  "await test_analyzer()"
111
  ]
test_scraper.ipynb DELETED
@@ -1,127 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# Test CSS Zen Garden Scraper\n",
8
- "\n",
9
- "This notebook tests the functionality of our CSS Zen Garden scraper."
10
- ]
11
- },
12
- {
13
- "cell_type": "code",
14
- "execution_count": 1,
15
- "metadata": {},
16
- "outputs": [],
17
- "source": [
18
- "!playwright install chromium"
19
- ]
20
- },
21
- {
22
- "cell_type": "code",
23
- "execution_count": 1,
24
- "metadata": {},
25
- "outputs": [
26
- {
27
- "name": "stdout",
28
- "output_type": "stream",
29
- "text": [
30
- "Testing scraper with design 220...\n",
31
- "Response status: 200\n",
32
- "\n",
33
- "Found elements:\n",
34
- "h1: CSS Zen Garden\n",
35
- "author: Dave Shea\n",
36
- "Success!\n",
37
- "Testing scraper with design 221...\n",
38
- "Response status: 200\n",
39
- "\n",
40
- "Found elements:\n",
41
- "h1: CSS Zen Garden\n",
42
- "author: Dave Shea\n",
43
- "Success!\n"
44
- ]
45
- }
46
- ],
47
- "source": [
48
- "from scraper import scrape_design\n",
49
- "import asyncio\n",
50
- "\n",
51
- "test_design_ids = [\"220\", \"221\"]\n",
52
- "\n",
53
- "async def test_scraper(ids):\n",
54
- " for test_design_id in ids:\n",
55
- " try:\n",
56
- " print(f\"Testing scraper with design {test_design_id}...\")\n",
57
- " await scrape_design(test_design_id)\n",
58
- " print(\"Success!\")\n",
59
- " except Exception as e:\n",
60
- " print(f\"Error: {str(e)}\")\n",
61
- "\n",
62
- "asyncio.run(test_scraper(test_design_ids))"
63
- ]
64
- },
65
- {
66
- "cell_type": "code",
67
- "execution_count": 3,
68
- "metadata": {},
69
- "outputs": [
70
- {
71
- "name": "stdout",
72
- "output_type": "stream",
73
- "text": [
74
- "Files created:\n",
75
- "['metadata.json', 'style.css']\n",
76
- "\n",
77
- "Metadata:\n",
78
- "{\n",
79
- " \"id\": \"221\",\n",
80
- " \"author\": \"Dave Shea\",\n",
81
- " \"url\": \"https://www.csszengarden.com/221\",\n",
82
- " \"css_url\": \"https://www.csszengarden.com/221/221.css\"\n",
83
- "}\n"
84
- ]
85
- }
86
- ],
87
- "source": [
88
- "# If successful, let's check what we got\n",
89
- "import json\n",
90
- "import os\n",
91
- "\n",
92
- "for id in test_design_ids:\n",
93
- " design_dir = f\"designs/{id}\"\n",
94
- " print(\"Files created:\")\n",
95
- " print(os.listdir(design_dir))\n",
96
- "\n",
97
- " # Display metadata\n",
98
- " with open(f\"{design_dir}/metadata.json\") as f:\n",
99
- " metadata = json.load(f)\n",
100
- " print(\"\\nMetadata:\")\n",
101
- " print(json.dumps(metadata, indent=2))\n",
102
- "\n"
103
- ]
104
- }
105
- ],
106
- "metadata": {
107
- "kernelspec": {
108
- "display_name": ".venv",
109
- "language": "python",
110
- "name": "python3"
111
- },
112
- "language_info": {
113
- "codemirror_mode": {
114
- "name": "ipython",
115
- "version": 3
116
- },
117
- "file_extension": ".py",
118
- "mimetype": "text/x-python",
119
- "name": "python",
120
- "nbconvert_exporter": "python",
121
- "pygments_lexer": "ipython3",
122
- "version": "3.11.11"
123
- }
124
- },
125
- "nbformat": 4,
126
- "nbformat_minor": 2
127
- }