save scraped result in database

This commit is contained in:
hilmanski
2023-10-05 10:13:11 +08:00
parent 0bca8f22d7
commit 4baa19e6ed
5 changed files with 37 additions and 11 deletions
+4 -1
View File
@@ -13,7 +13,10 @@ Surfer SEO, Frase io, ClearScope, NeuronWriter, etc.. (of course they offer more
- This is for personal usage, no authentication setup needed in the app itself.
- Sign up to [SerpApi](https://serpapi.com) to get FREE Serp search results credit
![sample free content optimization tool](/assets/content-editor-sample.webp)
![sample free content optimization tool](https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExanI5bm5yYzg1ZGg0OWhzMzcycnltZ2EzYzdkeGRmanZpOWZ2MXZnayZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/nenLVfRi9euvXekbQC/giphy.gif)
<!-- ![sample free content optimization tool](/assets/content-editor-sample.webp) -->
## Status
Under heavy development. Not for production.
+1
View File
@@ -11,6 +11,7 @@ class Post(SQLModel, table=True):
search_query: dict = Field(sa_column=Column(JSON))
search_result: dict = Field(sa_column=Column(JSON))
choosen_links: dict = Field(sa_column=Column(JSON))
links_scrape_result: dict = Field(sa_column=Column(JSON))
createdAt: datetime = Field(default_factory=datetime.utcnow)
updatedAt: datetime = Field(default_factory=datetime.utcnow)
+19 -6
View File
@@ -124,8 +124,16 @@ def deletePost(post_id: str):
@app.get('/scrape/{post_id}')
async def scrape(post_id: str):
post = get_post(post_id)
links = post.choosen_links
# Return early if exists
if post.links_scrape_result:
return {
"status": "success",
"data": post.links_scrape_result
}
# Scrape links if new
links = post.choosen_links
lang = post.search_query['hl']
contentInfo = []
@@ -143,13 +151,18 @@ async def scrape(post_id: str):
topKeywords = _getTopKeywords(allKeywords)
averageWords = sum([content['totalWords'] for content in contentInfo]) / len(contentInfo)
links_scrape_result = {
"contentInfo": contentInfo,
"topKeywords": topKeywords,
"averageWords": averageWords
}
update_post(post_id, {
"links_scrape_result": links_scrape_result
})
return {
"status": "success",
"data": {
"contentInfo": contentInfo,
"topKeywords": topKeywords,
"averageWords": averageWords
}
"data": links_scrape_result
}
# Currently lang get from hl query parameter
+3 -2
View File
@@ -63,8 +63,8 @@ export default function AddKeyword() {
)
}
<p className="font-bold">Add New Content+</p>
<form action="#" className="p-5 border border-black rounded-xl">
<p className="font-bold text-xl">Add New Content+</p>
<div className="my-5">
<p className="">keyword you want to rank</p>
@@ -121,6 +121,7 @@ export default function AddKeyword() {
Submit
</button>
</div>
</form>
</div>
)
}
+10 -2
View File
@@ -162,13 +162,21 @@ export default function Sidebar({
{
menu == 'terms' && (
<Terms result={result} />
<>
{
loading ? <p>Loading ... (Up to 1 minutes) </p> : <Terms result={result} />
}
</>
)
}
{
menu == 'outline' && (
<Outline result={result} />
<>
{
loading ? <p>Loading ... (Up to 1 minutes)</p> : <Outline result={result} />
}
</>
)
}