Skip to content

Commit 1eb3d88

Browse files
committed
Re-organize file structure
1 parent 97e67ac commit 1eb3d88

34 files changed

+868
-473
lines changed

.gitignore

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ db.sqlite3-journal
6464
# Flask stuff:
6565
instance/
6666
.webassets-cache
67+
flask_session/
68+
/*_session/
6769

6870
# Scrapy stuff:
6971
.scrapy
@@ -137,6 +139,7 @@ venv.bak/
137139

138140
# mkdocs documentation
139141
/site
142+
/zite
140143

141144
# mypy
142145
.mypy_cache/
@@ -159,16 +162,5 @@ cython_debug/
159162
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160163
#.idea/
161164

162-
####################################################
163-
# My adds
164-
165165
# macOS
166166
.DS_Store
167-
168-
# Flask
169-
flask_session/
170-
/*_session/
171-
172-
sketch*
173-
zketch*
174-
####################################################

.pylintrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[MESSAGES CONTROL]
2+
disable=line-too-long
3+
disable=protected-access
4+
disable=bare-except

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ As of v3.0.0-beta.1, the following `OUTPUT` types can be requested from exposed
2727

2828
More coming soon!
2929

30-
![Portfoliofy](/images/portfoliofy1.png)
30+
![Portfoliofy](/docs/portfoliofy1.png)
3131

3232
More screenshots below.
3333

@@ -106,7 +106,7 @@ More screenshots below.
106106
1. **Start the live server**
107107

108108
```bash
109-
uvicorn app.main:app --reload
109+
uvicorn api.portfoliofy:app --reload
110110
```
111111

112112
2. **Access the documentation user interfaces**
@@ -215,11 +215,11 @@ Improvements and new features development are ongoing.
215215
216216
## Screenshots
217217
218-
![Portfoliofy](/images/portfoliofy2.png)
218+
![Portfoliofy](/docs/portfoliofy2.png)
219219
220-
![Portfoliofy](/images/portfoliofy3.png)
220+
![Portfoliofy](/docs/portfoliofy3.png)
221221
222-
![Portfoliofy](/images/portfoliofy4.png)
222+
![Portfoliofy](/docs/portfoliofy4.png)
223223
224224
<https://github.com/ggeerraarrdd/portfoliofy/assets/50889794/c93ae299-1e76-42c1-b297-713a923eab79>
225225
File renamed without changes.

api/core/config/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
TD
3+
"""
4+
5+
from .config import settings_devices

app/settings.py renamed to api/core/config/config.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
# ################################################## #
1+
# #########################################################################
22
#
3-
# DO NOT EDIT
3+
# WARNING: DO NOT MODIFY THIS CONFIG FILE.
44
#
5-
# ################################################## #
5+
# Manual modifications can cause unintended behavior.
6+
#
7+
# #########################################################################
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
618
settings_devices = {
719
"desktop": {
820
"filename_large": "screenshot_desktop_large.png",
@@ -82,4 +94,4 @@
8294
"height_small": None,
8395
"small_height_crop": None,
8496
},
85-
}
97+
}

api/core/utils/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
TD
3+
"""
4+
5+
from .utils import get_screenshot
6+
from .utils import get_screenshot_full
7+
from .utils import get_screenshot_full_chrome
8+
from .utils import get_base
9+
from .utils import get_overlay
10+
from .utils import get_final_temp
11+
from .utils import get_final
12+
from .utils import cleanup
13+
14+
# Define what should be available when using "from .helpers import *"
15+
__all__ = ['get_screenshot',
16+
'get_screenshot_full',
17+
'get_screenshot_full_chrome',
18+
'get_base',
19+
'get_overlay',
20+
'get_final_temp',
21+
'get_final',
22+
'cleanup']

app/helpers.py renamed to api/core/utils/utils.py

Lines changed: 70 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
import os
2-
import json
1+
"""
2+
TD
3+
"""
4+
5+
# Python Standard Libraries
36
import base64
7+
import json
8+
import os
49
from time import sleep
10+
11+
# Third-Party Libraries
12+
from cairosvg import svg2png
13+
from PIL import Image
514
from selenium import webdriver
615
from selenium.webdriver.chrome.service import Service
716
from selenium.webdriver.chrome.options import Options
8-
from PIL import Image
9-
from cairosvg import svg2png
1017

1118

12-
def get_screenshot(url, wait, directory, settings_devices):
1319

20+
21+
22+
23+
24+
25+
26+
27+
def get_screenshot(url, wait, directory, settings_devices):
28+
"""
29+
TD
30+
"""
1431
# Set options
1532
options = Options()
1633
options.add_argument(f"--window-size={settings_devices['width_large']},{settings_devices['height_large']}")
17-
options.add_argument(f"--no-sandbox")
18-
options.add_argument(f"--headless")
19-
options.add_argument(f"--hide-scrollbars")
34+
options.add_argument("--no-sandbox")
35+
options.add_argument("--headless")
36+
options.add_argument("--hide-scrollbars")
2037

2138
try:
2239
# Set Chromedriver path
@@ -30,7 +47,7 @@ def get_screenshot(url, wait, directory, settings_devices):
3047

3148
# Open Chrome webdriver
3249
driver = webdriver.Chrome(options=options)
33-
50+
3451
# Take screenshot
3552
driver.get(url)
3653
sleep(wait)
@@ -46,11 +63,13 @@ def get_screenshot(url, wait, directory, settings_devices):
4663

4764

4865
def get_screenshot_full(url, wait, directory, settings_devices):
49-
66+
"""
67+
TD
68+
"""
5069
options = Options()
51-
options.add_argument(f"--no-sandbox")
52-
options.add_argument(f"--headless=new")
53-
options.add_argument(f"--hide-scrollbars")
70+
options.add_argument("--no-sandbox")
71+
options.add_argument("--headless=new")
72+
options.add_argument("--hide-scrollbars")
5473

5574
try:
5675
# Set Chromedriver path
@@ -60,7 +79,7 @@ def get_screenshot_full(url, wait, directory, settings_devices):
6079
driver = webdriver.Chrome(service=service, options=options)
6180
except:
6281
# Open Chrome webdriver
63-
driver = webdriver.Chrome(options=options)
82+
driver = webdriver.Chrome(options=options)
6483

6584
# Open Chrome webdriver
6685
driver = webdriver.Chrome(options=options)
@@ -70,7 +89,7 @@ def get_screenshot_full(url, wait, directory, settings_devices):
7089
sleep(wait)
7190

7291
fname_out_full_screenshot_png = settings_devices["filename_large"]
73-
92+
7493
png = get_screenshot_full_chrome(driver)
7594
with open(f"{directory}/{fname_out_full_screenshot_png}", 'wb') as f:
7695
f.write(png)
@@ -81,8 +100,10 @@ def get_screenshot_full(url, wait, directory, settings_devices):
81100

82101

83102
def get_screenshot_full_chrome(driver) :
84-
85-
# Function adapted from StackOverflow answer
103+
"""
104+
TD
105+
"""
106+
# Function adapted from StackOverflow answer
86107
# https://stackoverflow.com/questions/45199076/take-full-page-screenshot-in-chrome-with-selenium/45201692#45201692
87108

88109
def send(cmd, params):
@@ -120,14 +141,16 @@ def evaluate(script):
120141

121142

122143
def get_base(post, directory, svg, svg_fname, png_fname):
123-
144+
"""
145+
TD
146+
"""
124147
# Create SVG file
125-
with open(f"{directory}/{svg_fname}", "w") as file:
148+
with open(f"{directory}/{svg_fname}", "w", encoding="utf-8") as file:
126149
file.write(svg)
127-
150+
128151
# Convert to SVG to PNG
129-
svg2png(url=f"{directory}/{svg_fname}",
130-
write_to=f"{directory}/{png_fname}",
152+
svg2png(url=f"{directory}/{svg_fname}",
153+
write_to=f"{directory}/{png_fname}",
131154
background_color=post["doc_fill_color"])
132155

133156
# Delete SVG file
@@ -137,12 +160,14 @@ def get_base(post, directory, svg, svg_fname, png_fname):
137160

138161

139162
def get_overlay(directory, fname_input, fname_output, new_width, height_crop):
140-
163+
"""
164+
TD
165+
"""
141166
# Open the PNG image
142167
image = Image.open(f"{directory}/{fname_input}")
143168

144169
# Determine aspect ratio
145-
aspect_ratio = image.height / image.width
170+
aspect_ratio = image.height / image.width
146171

147172
# Set new height
148173
new_height = int(new_width * aspect_ratio)
@@ -161,7 +186,9 @@ def get_overlay(directory, fname_input, fname_output, new_width, height_crop):
161186

162187

163188
def get_final_temp(base, overlay, lat, lng, directory_path, new_file_name):
164-
189+
"""
190+
TD
191+
"""
165192
# Open the base image
166193
base_image = Image.open(base)
167194

@@ -181,34 +208,37 @@ def get_final_temp(base, overlay, lat, lng, directory_path, new_file_name):
181208

182209

183210
def get_final(directory, filename_input, filename_output, post):
184-
211+
"""
212+
TD
213+
"""
185214
right = post["doc_pad_h"]
186215
left = post["doc_pad_h"]
187216
top = post["doc_pad_v"]
188217
bottom = post["doc_pad_v"]
189218
color = post["doc_fill_color"]
190219

191-
image = Image.open(f"{directory}/{filename_input}")
192-
193-
width, height = image.size
194-
195-
new_width = width + right + left
196-
new_height = height + top + bottom
197-
198-
result = Image.new(image.mode, (new_width, new_height), color)
199-
200-
result.paste(image, (left, top))
201-
202-
result.save(f"{directory}/{filename_output}")
220+
image = Image.open(f"{directory}/{filename_input}")
221+
222+
width, height = image.size
223+
224+
new_width = width + right + left
225+
new_height = height + top + bottom
226+
227+
result = Image.new(image.mode, (new_width, new_height), color)
228+
229+
result.paste(image, (left, top))
230+
231+
result.save(f"{directory}/{filename_output}")
203232

204233
return 1
205234

206235

207236
def cleanup(directory_path, file):
237+
"""
238+
TD
239+
"""
208240
try:
209241
os.remove(f"{directory_path}/{file}")
210242
return f"{file} has been deleted"
211243
except FileNotFoundError:
212244
return f"{file} not in directory"
213-
214-

api/domain/schemas/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
TD
3+
"""
4+
5+
from .schemas import PortfoliofyRequest

api/domain/schemas/schemas.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
TD
3+
"""
4+
5+
from pydantic import BaseModel, HttpUrl, constr, conint, Field
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
class PortfoliofyRequest(BaseModel):
17+
"""
18+
TD
19+
"""
20+
# pylint: disable-all
21+
request: bool = Field(False, description='Request flag')
22+
remote_url: HttpUrl = Field("https://ggeerraarrdd.github.io/", description="Valid and accessible URL")
23+
wait: conint(gt=0, lt=101) = Field(2, description="Wait time for screenshot") # type: ignore[reportInvalidTypeForm]
24+
format: str = Field("png", pattern="^(png)$", description="Output file format")
25+
doc_pad_h: conint(gt=0, lt=1001) = Field(300, description="Padding value for horizontal dimension") # type: ignore[reportInvalidTypeForm]
26+
doc_pad_v: conint(gt=0, lt=1001) = Field(200, description="Padding value for vertical dimension") # type: ignore[reportInvalidTypeForm]
27+
doc_fill_color: constr(pattern=r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$") = Field("#ffffff", description="RGB hexadecimal value") # type: ignore[reportInvalidTypeForm]
28+
base_stroke_color: constr(pattern=r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$") = Field("#23445d", description="RGB hexadecimal value") # type: ignore[reportInvalidTypeForm]
29+
base_fill_color: constr(pattern=r"^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$") = Field("#bac8d3", description="RGB hexadecimal value") # type: ignore[reportInvalidTypeForm]

0 commit comments

Comments
 (0)