Skip to content

Instantly share code, notes, and snippets.

@SoulOfNoob
Last active January 5, 2021 13:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SoulOfNoob/16df708d463a73326ce72adde11ac09b to your computer and use it in GitHub Desktop.
Save SoulOfNoob/16df708d463a73326ce72adde11ac09b to your computer and use it in GitHub Desktop.
iOS 14 Vodafone tracking widget

Vodafone Bestellstatus widget

Intro

Das hier ist ein kleines widget für Scriptable unter iOS 14 welches die Versandinformationen von Vodafone ausliest und alle 60 Minuten aktualisert und anzeigt

Warum nur alle 60 Minuten? Weil Vodafone die Seite sperrt wenn man die zu oft aktualisiert ^^

Anforderungen

  • iOS 14
  • Scriptable version 1.5 (oder neuer)
  • Postleitzahl
  • SAPorderNo (aus dem bestellstatus link von vodafone )

Installation

  • Kopiere den Source code von unten (klick vorher auf Raw rechts neben dem dateinamen vodafone_tracking.js)
  • Öffne die Scriptable app
  • Klick auf das "+" Symbol oben rechts und füge das kopierte Skript ein
  • Ersetze ganz oben den text YOUR ORDER NO mit deiner SAPorderNo
  • Ersetze ganz oben den text YOUR POSTAL CODE mit deiner Postleitzahl
  • Klick auf den Titel des Skripts ganz oben und vergebe einen Namen (z.B. Vodafone)
  • Speichere das Skript durch Klick auf "Done" oben links
  • Gehe auf deinen iOS Homescreen und drücke irgendwo lang, um in den "wiggle mode" zu kommen (mit dem man auch die App Symbole anordnen kann)
  • Drücke das "+" Symbol oben links, blättere dann nach unten zu "Scriptable" (Liste ist alphabetisch), wähle die erste Widget Größe (small) und drück unten auf "Widget hinzufügen"
  • Drücke auf das Widget, um seine Einstellungen zu bearbeiten (optional lang drücken, wenn der Wiggle Modus schon beendet wurde)
  • Wähle unter "Script" das oben erstellte aus (Vodafone)

Changelog

  • 29.10.2020 15:11

    • Fehlermeldung im widget bei falscher Eingabe
    • DHL Informationen hinzugefügt
  • 30.10.2020 09:52

    • Aktuellste DHL Meldung wird jetzt angezeigt

Vielen dank an

marco79cgn dessen DM Klopapier widget mich auf die idee gebracht hat und dessen anleitung ich hier ein wenig kopiert habe https://gist.github.com/marco79cgn/23ce08fd8711ee893a3be12d4543f2d2

und

mrmartineau dessen youtube script ich auseinandergenommen habe um zu lernen wie diese widgets funktionieren https://github.com/mrmartineau/scriptable-widgets/tree/main/YoutubeChannelStats

// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: light-brown; icon-glyph: magic;
const SAP_ORDER_NO = 'YOUR ORDER NO'
const POSTAL_CODE = 'YOUR POSTAL CODE'
const UPDATE_INTERVAL = 1000*60*60 // 60 minutes
const USE_CACHED_DATA = true
let BG_COLOR = '#000000'
let fm = FileManager.iCloud()
let dir = fm.documentsDirectory()
const path = fm.joinPath(dir, "vodafone.json")
const JSONObject = await handleFile(fm, path)
const widget = await createWidget(JSONObject)
// Check if the script is running in
// a widget. If not, show a preview of
// the widget to easier debug it.
if (!config.runsInWidget) {
await widget.presentSmall()
}
// Tell the system to show the widget.
Script.setWidget(widget)
Script.complete()
async function createWidget(JSONObject) {
const bg = new Color(BG_COLOR)
const w = new ListWidget()
w.useDefaultPadding()
w.backgroundColor = bg
// w.refreshAfterDate = new Date(nextRefresh)
w.url = `https://www.vodafone.de/meinvodafone/bestellstatus-ergebnis.html?SAPorderNo=${SAP_ORDER_NO}&postalcode=${POSTAL_CODE}`
const row = w.addStack()
row.layoutHorizontally()
row.addSpacer()
if (typeof JSONObject.REQUESTSTATUS !== 'undefined' && JSONObject.REQUESTSTATUS == "Error") {
const _errorCode = JSONObject.ERRORDETAILS.ERRORCODE
const _errorMessage = JSONObject.ERRORDETAILS.ERRORMESSAGE
const code = w.addText("Error: " + _errorCode)
code.font = Font.regularSystemFont(20)
code.textColor = Color.white()
w.addSpacer()
const message = w.addText(_errorMessage)
message.font = Font.regularSystemFont(12)
message.textColor = Color.white()
} else if(typeof JSONObject.REQUESTSTATUS !== 'undefined' && JSONObject.REQUESTSTATUS == "Success") {
const _historytexts = JSONObject.ORDERSTATUSDETAILS.ORDERDATA[0].ORDERSTATUSINFORMATION.STATUSHISTORYTEXTS
const _statusid = JSONObject.ORDERSTATUSDETAILS.ORDERDATA[0].ORDERSTATUSINFORMATION.CURRENTSTATUSID
const _name = JSONObject.ORDERSTATUSDETAILS.ORDERDATA[0].PRODUCTDETAILS.DEVICE.PRODUCTNAME
const _leadtime = JSONObject.ORDERSTATUSDETAILS.ORDERDATA[0].PRODUCTDETAILS.DEVICE.LEADTIME
const _historytext = _historytexts[_statusid-1]
let fontSize = 20
let spacing = 4
if (_leadtime.length <= 5) {
fontSize = 30
spacing = 2
}
let lastUpdateString = new Date(JSONObject.lastUpdate)
lastUpdateString = lastUpdateString.toLocaleTimeString()
const lastUpdate = w.addText("Last Update: " + lastUpdateString)
lastUpdate.font = Font.regularSystemFont(6)
lastUpdate.textColor = Color.white()
w.addSpacer(6)
const name = w.addText(_name)
name.font = Font.regularSystemFont(10)
name.textColor = Color.white()
w.addSpacer(spacing)
const leadtime = w.addText(_leadtime)
leadtime.font = Font.mediumRoundedSystemFont(fontSize)
leadtime.textColor = Color.white()
w.addSpacer(spacing)
if (typeof JSONObject.ORDERSTATUSDETAILS.ORDERDATA[0].SHIPPINGINFORMATION !== 'undefined') {
const _logisticStatus = JSONObject.ORDERSTATUSDETAILS.ORDERDATA[0].SHIPPINGINFORMATION.LOGISTICSTATUS
const _lastLogisticStatus = _logisticStatus[0]
const _logisticsLocation = _lastLogisticStatus.LOCATION
const _logisticsText = _lastLogisticStatus.STATUSTEXT
const logisticsLocation = w.addText(_logisticsLocation)
logisticsLocation.font = Font.regularSystemFont(10)
logisticsLocation.textColor = Color.white()
const logisticsText = w.addText(_logisticsText)
logisticsText.font = Font.regularSystemFont(10)
logisticsText.textColor = Color.white()
} else {
const historytext = w.addText(_historytext)
historytext.font = Font.regularSystemFont(10)
historytext.textColor = Color.white()
}
} else if(typeof JSONObject.REQUESTSTATUS === 'undefined' && typeof JSONObject.PRODUCTDETAILS.DEVICE.LEADTIME !== 'undefined') {
// delete file
const err = w.addText("please delete vodafone.json")
err.font = Font.regularSystemFont(10)
err.textColor = Color.white()
}
return w
}
async function handleFile(fm, path) {
let JSONObject = JSON.parse('{}')
if (fm.fileExists(path)) { // if file exists
JSONObject = readJSON(path) // read file
if (typeof JSONObject.lastUpdate === 'undefined' || JSONObject.lastUpdate + UPDATE_INTERVAL < Date.now()) {
// update needed
console.log('updating')
let json = await fetchJSON()
if (json === false) {
console.log('update failed')
} else {
JSONObject = json
}
saveJSON(path, JSONObject)
}
// to update old file versions
if(typeof JSONObject.REQUESTSTATUS !== 'undefined') {
return JSONObject
}
}
// no file available
console.log('updating')
let json = await fetchJSON()
// await QuickLook.present(json)
if (json === false) {
console.log('update failed')
} else {
JSONObject = json
}
// only save to file when request is success
if (typeof JSONObject.REQUESTSTATUS !== 'undefined' && JSONObject.REQUESTSTATUS == "Success") {
saveJSON(path, JSONObject)
}
return JSONObject
}
async function fetchJSON() {
try {
const url = `https://www.vodafone.de/orderStatusService/?function=getOrderStatus&SAPorderNo=${SAP_ORDER_NO}&postalcode=${POSTAL_CODE}`
const req = new Request(url)
let json = await req.loadJSON()
if (typeof json.vfAjaxResponseParams !== 'undefined') {
//request returned JSON
json = json.vfAjaxResponseParams
return json
}
//request didn't return valid JSON
return false
}
catch(err) {
console.log(err.message)
return false
}
}
function saveJSON(JSONpath, JSONObject) {
JSONObject.lastUpdate = Date.now()
fm.writeString(JSONpath, JSON.stringify(JSONObject))
}
function readJSON(JSONpath) {
return JSON.parse(fm.readString(JSONpath))
}
@sahnebar
Copy link

Hey hey,
vielen Dank für das super script, nur irgendwie tut das nicht mehr... mach ich da irgendwie was falsch?
Ich habe lediglich oben die Bestellnummer und meine Postleizahl eingetragen. Es schlägt irgendwie immer bei Zeile 70 fehl.

grafik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment