Skip to content

Instantly share code, notes, and snippets.

@haubar
Last active November 8, 2023 08:54
Show Gist options
  • Save haubar/6baf60bc537d14f31dbff6cc31f00389 to your computer and use it in GitHub Desktop.
Save haubar/6baf60bc537d14f31dbff6cc31f00389 to your computer and use it in GitHub Desktop.
gcf sync
const axios = require('axios')
const qs = require('qs')
const airtable = require('airtable')
exports.stockNum = async(req, res) => {
return getlist(req, res)
}
const stockTable = new airtable({
apiKey: process.env.airtableKey
}).base('app2oVW62FODpXmq0')
const getUrl = async(url, data='', headers='', method='GET') => {
headers = headers ? headers : {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'}
const options = {
method: method,
headers: headers,
data: data,
url
}
return await axios(options)
.then(async (res) => {
return res.data
})
.catch(async (err) => {
await setTimeout(() => console.log(' To Reconnect !'), 6000);
throw new Error(err)
})
}
const getlist = async(req, res) => {
let headers = {'User-Agent':process.env.COMMAND_WGET_HEADER}
let url = process.env.STOCK_NUM_URL
let json = await getUrl(url, '', headers)
await syncTable(json)
// res.status(200).send(json)
}
const syncTable = async(data) => {
await stockTable.createRecordAsync({
"name" : XXX,
})
await stockTable.updateRecordAsync(id, {
"name" : XXX,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment