Skip to content
Backend to upload data to iCloud's servers
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
delete_today.js
upload_data.js

README.md

Neural Bikes Backend

ko-fi

Backend service written in Node.JS, helps manage the data for Neural Bikes, a bike sharing availability prediction service. All the data is uploaded to Apple's CloudKit servers.

This collection of scrips upload the actual availability for the day and the predictionstailored for each station. The data is uploaded to Apple's iCloud servers and then the users can get the data from the app or web.

This uses the JavaScript librery that Apple provides to interact with iCloud, CloudKit.JS. It can be downloaded from a CDN to later be embedded in your script.

This is not a solution for everybody but a sample to show how this project works and provide another example on how to use CloudKit.JS.

Structure

  • upload_data.js: Uploads data for every station, queries InfluxDB

Today

Run every ten minutes, queries the InfluxDB database for trhe availability for that day.

  1. Get all the available stations in the InfluxDB database.

SHOW TAG VALUES FROM bikes WITH KEY = station_name

  1. Query today's availabilty for each station.

  2. Connect and authenticate to CloudKit.

  3. Get the recordChangeTag for each station. If none is retrieved no record was found in the database for that station.

  4. Construct the new record with the updated values and the recordChangeTag if needed and upload it to CloudKit

Just if needed all the available records can be deleted from either the development or production environment using the delete_today.js script.

Requirements

  • Server-to-Server Key: Allows this server-side application to read and write data in the public database of an iCloud container and environment.
  • API Token: Allows a web frontend to send request to the iCloud container and environment
  • ECKEY

Running

This script is run as a cronjob so it uploads the data every Xminutes, to run it:

node today.js development/production city DATABASE

Dependencies

You can’t perform that action at this time.