Skip to content

Instantly share code, notes, and snippets.

@filippobenozzi
Last active December 18, 2023 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filippobenozzi/533458484091c826d04351f9f2bda4ad to your computer and use it in GitHub Desktop.
Save filippobenozzi/533458484091c826d04351f9f2bda4ad to your computer and use it in GitHub Desktop.
scriptable-iliad.js
//
// Iliad data usage widget - filippo.im
// Set here your Iliad credentials
// v1.5
//
const USERNAME = '<YOUR-USERNAME>';
const PASSWORD = '<YOUR-PASSWORD>';
//
// Don't modify after here
//
const ILIAD_URL = 'https://www.iliad.it/account/consumi-e-credito';
const createWidget = async () => {
const result = await getIliadData()
const list = new ListWidget()
list.backgroundColor = new Color('#212121')
list.refreshAfterDate = new Date(Date.now() + 30 * 60 * 1000)
if (result.match(/Linea: [0-9]*.[0-9]*.[0-9]*/)) {
const number = result.match(/Linea: [0-9]*.[0-9]*.[0-9]*/)[0];
const dateRenew = result.match(/[0-9]{2}\/[0-9]{2}\/[0-9]{4}/)[0];
const calls = result.match(/Chiamate:\n[0-9]*[a-z]*.+s/)[0];
const messages = result.match(/[0-9]{1,4} SMS/)[0];
const gb_italy = result.match(/[0-9]*,*[0-9]*[a-zA-Z]*\n * \/ [0-9]+GB/)[0]
const gb_eu = result.match(/[0-9]*,*[0-9]*[a-zA-Z]* \/ [0-9]GB/)[0]
console.log(gb_italy)
const header = list.addText('ILIAD')
header.font = Font.boldSystemFont(13)
header.textColor = new Color('#e53935')
const value_number = list.addText(number.replace('Linea: ','').replace(' ','').replace(' ',''))
value_number.font = Font.boldSystemFont(10)
value_number.textColor = new Color('#e53935')
list.addSpacer()
const value_calls = list.addText('☎️ ' + calls.replace(/^\s+|\s+$/gm,'').replace(/(\r\n|\n|\r)/gm, "").replace('Chiamate:',''))
value_calls.font = Font.boldSystemFont(12)
list.addSpacer(3)
const value_messages = list.addText('💬 ' + messages)
value_messages.font = Font.boldSystemFont(12)
list.addSpacer(3)
const value_gb_italy = list.addText('🇮🇹 ' + gb_italy.replace(/^\s+|\s+$/gm,'').replace(/(\r\n|\n|\r)/gm, "").replace(/,[0-9]*/,''))
value_gb_italy.font = Font.boldSystemFont(12)
list.addSpacer(3)
const value_gb_eu = list.addText('🇪🇺 ' + gb_eu.replace(/,[0-9]*/,''))
value_gb_eu.font = Font.boldSystemFont(12)
list.addSpacer()
const label_renew = list.addText('Rinnovo: ' + dateRenew)
label_renew.font = Font.boldSystemFont(11)
label_renew.font = Font.italicSystemFont(11)
} else {
list.addText('Data not available')
}
return list
}
const getIliadData = async () => {
const r = new Request(ILIAD_URL)
r.addParameterToMultipart('login-ident',USERNAME)
r.addParameterToMultipart('login-pwd',PASSWORD)
r.method = 'post'
try {
let result = await r.loadString()
result = result.replace(/(<([^>]+)>)/gi, "");
return String(result)
} catch (err) {
return undefined
}
}
const widget = await createWidget()
if (!config.runsInWidget) await widget.presentSmall()
Script.setWidget(widget)
Script.complete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment