// Imports the Google Cloud client library
const Datastore = require('@google-cloud/datastore')

// Your Google Cloud Platform project ID
const projectId = 'pirula-time'

// Instantiates a client
const datastore = Datastore({
  projectId: projectId
})

// The kind for the new entity
const kind = 'time'
// The name/ID for the new entity
const name = 'average'
// The Cloud Datastore key for the new entity
const key = datastore.key([kind, name])

function scrape() {
  const data = {
    average: 3200,
  }
  return data
}

/**
 * Triggered from a message on a Cloud Pub/Sub topic.
 *
 * @param {!Object} event The Cloud Functions event.
 * @param {!Function} The callback function.
 */
exports.subscribe = function subscribe(event, callback) {
  console.log("START")
  // The Cloud Pub/Sub Message object.
  const pubsubMessage = event.data

  const data = scrape()

  // Prepares the new entity
  const average = {
    key: key,
    data: {
      val: data.average
    }
  }

  // Saves the entity
  datastore.save(average)
    .then(() => {
      console.log(`Saved ${average.key.name}: ${average.data}`)
    })
    .catch((err) => {
      console.error('ERROR:', err)
    })

  // Don't forget to call the callback.
  callback()
};
@@ -1,47 +1,4 @@
-// Imports the Google Cloud client library%0A
 cons
@@ -49,50 +49,8 @@
 re')
-%0A%0A// Your Google Cloud Platform project ID
 %0Acon
@@ -81,34 +81,8 @@
 ime'
-%0A%0A// Instantiates a client
 %0Acon
@@ -139,169 +139,42 @@
 %7D)%0A%0A
-// The kind for the new entity%0Aconst kind = 'time'%0A// The name/ID for the new entity%0Aconst name = 'average'%0A// The Cloud Datastore key for the new entity%0Aconst k
+const kind = 'time'%0Aconst averageK
 ey =
@@ -195,20 +195,25 @@
 (%5Bkind, 
-name
+'average'
 %5D)%0A%0Afunc
@@ -262,10 +262,10 @@
 ge: 
-32
+18
 00,%0A
@@ -289,380 +289,136 @@
 %0A%7D%0A%0A
-/**%0A * Triggered from a message on a Cloud Pub/Sub topic.%0A *%0A * @param %7B!Object%7D event The Cloud Functions event.%0A * @param %7B!Function%7D The callback function.%0A */%0Aexports.subscribe = function subscribe(event, callback) %7B%0A  console.log(%22START%22)%0A  // The Cloud Pub/Sub Message object.%0A  const pubsubMessage = event.data%0A%0A  const data = scrape()%0A%0A  // Prepares the new entity
+exports.doIt = function doIt(req, res) %7B%0A  console.log(%22DOIN' IT!%22)%0A  const message = req.body.message%0A%0A  const data = scrape()%0A
 %0A  c
@@ -422,23 +422,24 @@
   const 
+s
 ave
-rage
+Data
  = %7B%0A   
@@ -444,17 +444,24 @@
    key: 
-k
+averageK
 ey,%0A    
@@ -507,30 +507,8 @@
  %7D%0A%0A
-  // Saves the entity%0A
   da
@@ -520,23 +520,24 @@
 re.save(
+s
 ave
-rage
+Data
 )%0A    .t
@@ -558,62 +558,62 @@
     
-console.log(%60Saved $%7Baverage.key.name%7D: $%7Baverage.d
+res.status(200).send(%60Saved $%7BJSON.stringify(saveD
 ata
+)
 %7D%60)%0A
@@ -651,96 +651,61 @@
     
-console.error('ERROR:', err)%0A    %7D)%0A%0A  // Don't forget to call the callback.%0A  callback(
+res.status(500).send('Error: ' + err.toString())%0A    %7D
 )%0A%7D
-;

Change scrapper trigger to http request