Created
August 1, 2021 14:54
-
-
Save Romern/0592ca7999f2c81f9f5d3294fd20d964 to your computer and use it in GitHub Desktop.
Short nodejs script which dumps all menus for lieferando restaurants in your area, and python script which puts them crudely into a csv file for eaier inspection.
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
import {inspect} from 'util'; | |
import {Takeaway, TakeawayConfig} from 'takeaway'; | |
(async () => { | |
try { | |
const plz = "52080"; | |
const coordLNG = '50.7'; | |
const coordLAT = '6.0'; | |
// Initialize configuration | |
// See `src/config.js` for defaults | |
const config = new TakeawayConfig({ | |
language: 'de', | |
url: 'https://de.citymeal.com/android/android.php' | |
}); | |
// Initialize Takeaway API | |
const takeaway = new Takeaway(config); | |
// Fetch country | |
const country = await takeaway.getCountryById('DE'); | |
// Request restaurants list for area | |
const restaurants = await country.getRestaurants(plz, coordLNG, coordLAT); | |
const allMenus = restaurants.map(async restaurant => { | |
await restaurant.getMenu(plz); | |
}); | |
await Promise.all(allMenus) | |
console.log(JSON.stringify(restaurants)); | |
} catch (err) { | |
console.error(err); | |
console.log(JSON.stringify(restaurants)); | |
} | |
})(); |
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
import json | |
data = json.load(open("menuRestaurantAll.json","r")) | |
properData = {d["data"]["name"]:{c["data"]["name"]:[m["data"]["name"] for m in c["products"]] for c in d["categories"]} for d in data} | |
reversedData = [(p,c,r) for r in properData for c in properData[r] for p in properData[r][c]] | |
goodCSV = "\n".join([";".join([t for t in p]) for p in reversedData]) | |
open("allMenuesCSVFlattened.csv","w").write(goodCSV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment