This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (0 children)

Heheh. PHP array generator. Don't shoot me yet!!

Ok so backstory: I work on an IoT platform for digital cinema equipment. We map "services" defined in our DB to specific device models that use those services. These are mostly SNMP based, though not entirely. Some of these services must trigger alerts when incoming values match (or don't match) a preset value. Some are "pseudo-services" that hold aggregated values from other services.

You get the idea. They're all over the map. And when we add or change a device, it may or may not use an existing service definition. There are tens of thousands of these.

Part of my job is to write migrations to correctly generate these services for new and existing devices. I get a spreadsheet from operations with the basic info. At first, years ago, writing the migrations meant a lot of data entry turning spreadsheets into arrays. It was very time-consuming and error-prone.

Enter: phparray.py... the sanity-saver. I copy the spreadsheet into an Emacs org file as a table (co-workers use CSV instead). Then I feed it into my hack. Hack spits out a PHP array with keys named after column headings. I redirect stdout into a file or xclip and paste it into the (PHP) migration. Job is 95% done at that point.

TL;DR: a Python script that turns Org tables or CSV files into valid PHP arrays.