Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Commit f2f89ac

Browse files
committed
fix: some changes
1 parent 1d134a8 commit f2f89ac

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
</p>
44

55
# CoinMarketCap Scraper
6-
_Actually **outdated**, see this [issue](https://github.com/Sorok-Dva/coinmarketcap-scraper/issues/1)_
76

87
## Description
98
This application is a scraper built with puppeteer that will send on discord your crypto assets balance with screenshot or simply with text.
109

10+
You can also retrieve your assets list in image (⚠If you have lot of assets in your wallet, the image preview sent on discord may be unreadable, but no panic, just open the original in your browser and you'll be able to perfectly zoom)
11+
1112
It is highly recommended using this app under a process manager like pm2, as it become a background process that will run on your server.
1213
If you don't have a dedicated server that is always on, consider using [Heroku](https://www.heroku.com/).
1314

config/coinmarketcap.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const screenshotDOMElement = async (opts = {}) => {
1515
const y = box['y']
1616
const w = box['width'] + 15
1717
const h = box['height']
18-
await element.screenshot({ path: opts.path, 'clip': {'x': x, 'y': y, 'width': w, 'height': h} });
18+
await element.screenshot({ path: opts.path, 'clip': { 'x': x, 'y': y, 'width': w, 'height': h } })
1919
}
2020

2121
const CMC = {
@@ -83,16 +83,16 @@ const CMC = {
8383
console.log('set storage')
8484
localStorage.clear()
8585
localStorage.setItem('u', JSON.stringify(ls))
86-
}, ls);
86+
}, ls)
8787
await CMC.page.reload()
8888
},
8989
defineSettings: async () => {
9090
const cookies = [{
9191
'name': 'currency',
9292
'value': process.env.CMC_CURRENCY,
9393
}, {
94-
'name': 'cmc-theme',
95-
'value': process.env.CMC_LIGHTMODE,
94+
'name': process.env.CMC_LIGHTMODE,
95+
'value': 'night',
9696
}, {
9797
'name': 'cmc_gdpr_hide',
9898
'value': '1',
@@ -101,18 +101,22 @@ const CMC = {
101101
await CMC.page.setCookie(...cookies)
102102
},
103103
completLoginForm: async () => {
104-
await CMC.page
105-
.type('input[type="email"]', process.env.CMC_LOGIN, { delay: 25 })
106-
.then(async () => console.info('Username complete'))
107-
await CMC.page.waitForTimeout(500)
108-
await CMC.page
109-
.type('input[type="password"]', process.env.CMC_PASS, { delay: 25 })
110-
.then(async () => console.info('Password complete'))
111-
await CMC.page.waitForTimeout(2000)
104+
try {
105+
await CMC.page
106+
.type('input[type="email"]', process.env.CMC_LOGIN, { delay: 25 })
107+
.then(async () => console.log('Username complete'))
108+
await CMC.page.waitForTimeout(500)
109+
await CMC.page
110+
.type('input[type="password"]', process.env.CMC_PASS, { delay: 25 })
111+
.then(async () => console.log('Password complete'))
112+
await CMC.page.waitForTimeout(2000)
113+
} catch (e) {
114+
log('[completLoginForm] Error', e)
115+
}
112116
},
113117
popupLogin: async (text) => {
114118
try {
115-
const [button] = await CMC.page.$x(`//button[contains(., '${text}')]`);
119+
const [button] = await CMC.page.$x(`//button[contains(., '${text}')]`)
116120
if (button) {
117121
await button.click()
118122
await CMC.page.waitForSelector('input[type="email"]')
@@ -125,11 +129,10 @@ const CMC = {
125129
console.info('connected')
126130
} catch (e) {
127131
console.error('[login] Error', e)
128-
await CMC.close()
129132
}
130133
},
131134
deleteLeftNode: async () => {
132-
const xpath = "//span[contains(text(),'My Main Portfolio')]";
135+
const xpath = `//span[contains(text(),'My Main Portfolio')]`
133136
await CMC.page.evaluate(xpath => {
134137
const node = document.evaluate(
135138
xpath,
@@ -150,12 +153,12 @@ const CMC = {
150153
const [timeRange] = await CMC.page.$x(`//span[contains(., '${process.env.CMC_TIMERANGE}')]`);
151154
if (timeRange) {
152155
await timeRange.click()
153-
await CMC.page.waitForFunction(() => document.querySelector("body").innerText.includes("Recalculating") === false)
156+
await CMC.page.waitForFunction(() => document.querySelector("body").innerText.includes('Recalculating') === false)
154157
}
155158
const time = new Date()
156159
const timeString = `${time.getDate()}-${time.getMonth()}-${time.getFullYear()}`
157160
const filname = `data/screenshots/CMC_Result_${timeString}.png`
158-
const xpath = "//span[contains(text(),'Current Balance')]";
161+
const xpath = `//span[contains(text(),'Current Balance')]`
159162
const nodeClasses = await CMC.page.evaluate(xpath => {
160163
return document.evaluate(
161164
xpath,
@@ -170,11 +173,10 @@ const CMC = {
170173
path: filname,
171174
selector,
172175
})
173-
discord('_The preview may be unreadable as it, just open the image in your browser so you will be able to zoom and perfectly read your assets list_', filname)
176+
discord('', filname)
174177
if (process.env.CMC_SEND_ASSETS_LIST === 'true') await CMC.getAssetsScreenshot()
175178
} catch (e) {
176-
console.error('[getFundScreenshot] Error', e)
177-
await CMC.close()
179+
console.log('[getFundScreenshot] Error', e)
178180
}
179181
},
180182
getAssetsScreenshot: async () => {
@@ -184,7 +186,7 @@ const CMC = {
184186
const time = new Date()
185187
const timeString = `${time.getDate()}-${time.getMonth()}-${time.getFullYear()}`
186188
const filname = `data/screenshots/CMC_Assets_${timeString}.png`
187-
const xpath = "//p[contains(text(),'Your Assets')]";
189+
const xpath = `//p[contains(text(),'Your Assets')]`
188190
const nodeClasses = await CMC.page.evaluate(xpath => {
189191
return document.evaluate(
190192
xpath,
@@ -199,10 +201,9 @@ const CMC = {
199201
path: filname,
200202
selector,
201203
})
202-
await discord('', filname)
204+
discord('_The preview may be unreadable as it, just open the image in your browser so you will be able to zoom and perfectly read your assets list_', filname)
203205
} catch (e) {
204-
console.error('[getFundScreenshot] Error', e)
205-
await CMC.close()
206+
console.log('[getAssetsScreenshot] Error', e)
206207
}
207208
},
208209
getFundText: async () => {

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "coinmarketcap-scraper",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "A scraper built with puppeteer to retrieve your crypto assets balance / list on discord",
55
"author": "Сорок два",
66
"private": true,

0 commit comments

Comments
 (0)