﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
15085	Fetch overpass turbo queries from OSM preferences API	Don-vip	team	"From #15057:

> Overpass turbo now has an option to save a query directly in the OSM account data. We could fetch that data (and in principle add new entries as well): ​https://www.openstreetmap.org/user/tyr_asd/diary/41793

This code allows to fetch overpass turbo queries (with r12502 + `overpass-turbo-lzw.js`):

{{{
#!java
            try {
                Map<String, String> map = new OsmServerUserPreferencesReader().fetchUserPreferences(NullProgressMonitor.INSTANCE);
                String scount = map.get(""overpass-ide_query-count"");
                if (scount != null) {
                    try {
                        ScriptEngine engine = new ScriptEngineManager().getEngineByName(""JavaScript"");
                        try (CachedFile cf = new CachedFile(""resource://data/overpass-turbo-lzw.js"");
                                Reader reader = cf.getContentReader()) {
                            engine.eval(reader);
                        }
                        Object base64 = engine.get(""Base64"");

                        for (int i = 0; i < Integer.parseInt(scount); i++) {
                            String v = map.get(""overpass-ide_query_"" + i + ""_0"");
                            int idx = v.indexOf(""p="") + 2;
                            int p = Integer.parseInt(v.substring(idx, v.indexOf('&', idx)));
                            idx = v.indexOf(""n="") + 2;
                            String name = v.substring(idx, v.indexOf('&', idx));
                            StringBuffer sb = new StringBuffer(v.substring(v.indexOf(""q="") + 2));
                            for (int j = 1; j < p ; j++) {
                                sb.append(map.get(""overpass-ide_query_"" + i + ""_"" + j));
                            }
                            String query = (String) ((Invocable) engine).invokeFunction(""lzw_decode"",
                                    ((Invocable) engine).invokeMethod(base64, ""decode"", sb.toString()));
                        }
                    } catch (NumberFormatException ex) {
                        Main.trace(ex);
                    }
                }
            } catch (OsmTransferException | ScriptException | NoSuchMethodException | IOException ex) {
                Main.error(ex);
            }
}}}

> We can add an extra button to fetch/sync them, but this would be a separate feature. The problem I see is that we should be consistent on where we store preferences: We currently only store all preferences locally. Best would be to allow the user to store all JOSM preferences to the server and be consistent there.
> PS: Wouldn't this be much cleaner using Regexp ({{{p=(\\d+)}}}, untested)?"	enhancement	new	normal		Core			mirrored_download overpass turbo	bastiK michael2402 Stereo
