-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from CheatSOL/develop
FEAT: 4주차 develop 브랜치 main 브랜치로 병합
- Loading branch information
Showing
28 changed files
with
1,095 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,4 +94,4 @@ function onListening() { | |
? 'pipe ' + addr | ||
: 'port ' + addr.port; | ||
debug('Listening on ' + bind); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
psycopg2-binary==2.9.9 | ||
gensim==4.3.2 | ||
pandas==2.2.2 | ||
psycopg2==2.9.9 | ||
psycopg2-binary==2.9.9 | ||
python-dotenv==1.0.1 | ||
scipy==1.10.0 | ||
scipy==1.12.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
const db = require("../models/DB"); | ||
|
||
async function getCache(keyword, social, period) { | ||
try { | ||
const cacheData = await db.Cache.findOne({ | ||
where: { | ||
keyword: keyword, | ||
social: social, | ||
period: period, | ||
}, | ||
order: [["updatedAt", "DESC"]], | ||
}); | ||
|
||
return cacheData; | ||
} catch (error) { | ||
console.log("cacheError", error); | ||
return null; | ||
} | ||
} | ||
|
||
async function setCache(keyword, social, period, data) { | ||
await db.Cache.create({ | ||
keyword: keyword, | ||
social: social, | ||
period: period, | ||
data: data, | ||
}); | ||
} | ||
|
||
async function updateCache(keyword, social, period, data) { | ||
await db.Cache.update( | ||
{ | ||
data: data, | ||
updatedAt: Date.now(), | ||
}, | ||
{ | ||
where: { | ||
keyword: keyword, | ||
social: social, | ||
period: period, | ||
}, | ||
} | ||
); | ||
} | ||
|
||
function isExpired(cache) { | ||
if (cache === null || cache === undefined) return true; | ||
const givenDate = new Date(cache.updatedAt); | ||
|
||
const expirationDate = new Date(givenDate.getTime() + 24 * 60 * 60 * 1000); | ||
|
||
const currentDate = new Date(); | ||
|
||
return expirationDate < currentDate; | ||
} | ||
|
||
module.exports = { getCache, setCache, updateCache, isExpired }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
const axios = require("axios"); | ||
const cheerio = require("cheerio"); | ||
|
||
function formatInstagramStyle(input) { | ||
let num = input[0]; | ||
let percentage = input[1] * 100; | ||
|
||
// 숫자를 적절한 단위로 축약 | ||
function formatNumber(number) { | ||
if (number >= 1e6) { | ||
return (number / 1e6).toFixed(1) + "M"; | ||
} else if (number >= 1e3) { | ||
return (number / 1e3).toFixed(1) + "K"; | ||
} else { | ||
return number.toString(); | ||
} | ||
} | ||
|
||
// 백분율로 변환 | ||
let formattedNum = formatNumber(num); | ||
let formattedPercentage = percentage.toFixed(0) + "%"; | ||
|
||
return [formattedNum, formattedPercentage]; | ||
} | ||
|
||
const formatDate = function formatDate(originalDate) { | ||
let year = parseInt(originalDate.slice(2, 4)); | ||
let month = parseInt(originalDate.slice(5, 7)); | ||
month++; | ||
let ans; | ||
if (month > 12) { | ||
month = 1; | ||
year++; | ||
} | ||
if (month < 10) { | ||
ans = year + ".0" + month; | ||
} else { | ||
ans = year + "." + month; | ||
} | ||
|
||
return ans; | ||
}; | ||
const getTagId = async function convertWordToTagId(word) { | ||
try { | ||
const { data } = await axios.get( | ||
` | ||
https://moana.mediance.co.kr/v1/instagram-tags/find?keyword=${encodeURI( | ||
word | ||
)}&uid=${process.env.INSTA_UID_KEY}&ip=${process.env.INSTA_IP}`, | ||
{ | ||
headers: { | ||
Authorization: process.env.INSTA_KEY, | ||
}, | ||
} | ||
); | ||
console.log("Daa:", data); | ||
return data.id; | ||
} catch (error) { | ||
console.error("Error fetching tag ID:", error); | ||
} | ||
}; | ||
|
||
const getTags = async function getHotHashTags(word) { | ||
try { | ||
const { data } = await axios.get( | ||
`https://moana.mediance.co.kr/v1/instagram-tags/find?keyword=${encodeURI( | ||
word | ||
)}&ip=${process.env.INSTA_IP}&uid=${process.env.INSTA_UID_KEY}`, | ||
{ | ||
headers: { | ||
Authorization: process.env.INSTA_KEY, | ||
}, | ||
} | ||
); | ||
// console.log("xdata);/ | ||
return data.instagramTag.instagramTagTree.engagementTags; | ||
} catch (error) { | ||
console.error("Error fetching hotTags data:", error); | ||
} | ||
}; | ||
const getTrend = async function getTrendWithTagId(id) { | ||
try { | ||
const { data } = await axios.get( | ||
`https://moana.mediance.co.kr/v1/instagram-tags/${id}/series-summary`, | ||
{ | ||
headers: { | ||
Authorization: process.env.INSTA_KEY, | ||
}, | ||
} | ||
); | ||
|
||
const trend = data.data.map((item) => { | ||
return { date: formatDate(item.statOn), posts: item.postCount }; | ||
}); | ||
|
||
return trend; | ||
} catch (error) { | ||
console.error("Error fetching trend data:", error); | ||
} | ||
}; | ||
|
||
const getTagInfo = async function getTagInfo(id) { | ||
try { | ||
const { data } = await axios.get( | ||
`https://moana.mediance.co.kr/v1/instagram-tags/${id}/summary?ip=${process.env.INSTA_IP}}`, | ||
{ | ||
headers: { | ||
Authorization: process.env.INSTA_KEY, | ||
}, | ||
} | ||
); | ||
|
||
return formatInstagramStyle([ | ||
data.postCount, | ||
data.instagramTag.instagramTagStat.engagementAvg / | ||
data.instagramTag.instagramTagStat.occupyTimeAvg, | ||
]); | ||
} catch (error) { | ||
console.error("Error fetching or parsing data:", error); | ||
return null; | ||
} | ||
}; | ||
const getInstagramInfo = async function scrapingInstagramSocialInfo(word) { | ||
try { | ||
const id = await getTagId(word); | ||
if (id) { | ||
const trendData = await getTrend(id); | ||
const topTags = (await getTags(word)).slice(0, 3); | ||
const tagInfo = await getTagInfo(id); | ||
|
||
return { id, trendData, topTags, tagInfo }; | ||
} else { | ||
console.log("No ID found for the given word."); | ||
} | ||
} catch (error) { | ||
console.error("Error in instagramInfo function:", error); | ||
} | ||
}; | ||
|
||
module.exports = { getInstagramInfo }; |
Empty file.
Oops, something went wrong.