Last active
August 15, 2025 23:57
-
-
Save hazycora/feb890c621bc258eafe48f9dd1a2e5b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const GEOSUBMIT_ENDPOINT = 'https://api.beacondb.net/v2/geosubmit' | |
| async function getPosition() { | |
| const locationResult = await Location.current() | |
| return { | |
| latitude: locationResult.latitude, | |
| longitude: locationResult.longitude, | |
| accuracy: locationResult.horizontalAccuracy, | |
| altitude: locationResult.altitude, | |
| altitudeAccuracy: locationResult.verticalAccuracy | |
| } | |
| } | |
| const position = await getPosition() | |
| const csv = args.plainTexts[0] | |
| function csvRowToValues(row) { | |
| return row.split(',').map(item => { | |
| item = item.trim() | |
| if (item.startsWith('"')) { | |
| return item.slice(1, -1) | |
| } | |
| return item | |
| }) | |
| } | |
| function csvToJson(csv) { | |
| csv = csv.trim() | |
| const lines = csv.split('\n') | |
| const header = lines.shift() | |
| const headerItems = csvRowToValues(header) | |
| const items = [] | |
| for (const line of lines) { | |
| const item = {} | |
| const values = csvRowToValues(line) | |
| for (const i in headerItems) { | |
| const key = headerItems[i] | |
| item[key] = values[i] | |
| } | |
| items.push(item) | |
| } | |
| return items | |
| } | |
| const wifiAccessPoints = csvToJson(csv).map(ap => { | |
| if (ap.SSID.endsWith("_nomap")) return | |
| return { | |
| ssid: ap.SSID, | |
| macAddress: ap.BSS, | |
| signalStrength: parseFloat(ap.RSSI), | |
| channel: parseFloat(ap.Channel) | |
| } | |
| }).filter(ap => ap) | |
| const geoSubmitItem = { | |
| timestamp: Date.now(), | |
| position, | |
| wifiAccessPoints | |
| } | |
| const geoSubmitBody = { | |
| items: [geoSubmitItem] | |
| } | |
| function sendNotification(title, subtitle, body) { | |
| const notification = new Notification() | |
| notification.title = title | |
| notification.subtitle = subtitle | |
| notification.body = body | |
| notification.schedule() | |
| } | |
| async function geoSubmitPost(body) { | |
| const req = new Request(GEOSUBMIT_ENDPOINT) | |
| req.method = 'post' | |
| req.headers = { | |
| 'User-Agent': 'Hazel-iOS-Script', | |
| 'Content-Type': 'application/json' | |
| } | |
| req.body = body | |
| const response = req.loadJSON() | |
| sendNotification("sent submission", '', 'response: ' + JSON.stringify(response)) | |
| } | |
| await geoSubmitPost(geoSubmitBody) | |
| Script.complete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment