Coder Social home page Coder Social logo

mhulse / kludgy Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 2.0 18.83 MB

Kludgy: A macOS Node.js module/app that generates a random Google Street View desktop wallpaper.

License: Apache License 2.0

JavaScript 100.00%
google google-maps experimental macos streetview maps equirectangular panorama nodejs

kludgy's Introduction

Kludgy (v2)

A macOS Node.js module/app that generates a random Google Street View desktop wallpaper.

This software is meant for educational purposes only. All images generated by this code are copyright to their respective owners. THIS REPOSITORY IS IN NO WAY SPONSORED, ENDORSED, ADMINISTERED BY OR ASSOCIATED WITH GOOGLE.

Use Kludy’s CLI to more easily run this package on your macOS.

For more information, check out this repo’s Wiki.

Examples

License

Copyright © 2016-19 Michael Hulse.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

kludgy's People

Contributors

mhulse avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

naoyeye

kludgy's Issues

More docs, usage and development

Need to move all dev-related docs to WIKI.

From there, make README specific to usage instructions for end user (like, how to install from GitHub repo, and how to get Google Maps API key).

Why doesn't the returned Lat Lon not find street view?

In kludgy.sh, I tried switching from ID to lat/long.

Just doesn't seem to work. I was hoping that would allow me to use any returned pano, vs just Google ones (see #4).

For example, if I remove the check for "Google" here:

if (coords.copyright == '© 2017 Google') {

And if you remove the first two args below, and replace with "lat,lon" (see docs for that lib):

kludgy/kludgy.sh

Lines 71 to 78 in fa39840

extract-streetview \
"$id" \
--id \
--quality 1 \
--format "jpg" \
--source "outdoor" \
--zoom max \
> "$image"

Unfortunately, pano not found when doing this.

I suspect it's due to user panos. I need to test by keeping the "Google" check and seeing if it just doesn't like lat/lon in general. If so, then I might suspect it's due to precision in the numbers?

/usr/local/lib/node_modules/kludgy/node_modules/zombie/lib/eventloop.js:594 throw error;

kludgy "api key redacted" /Users/djbeeker/Desktop/
/usr/local/lib/node_modules/kludgy/node_modules/zombie/lib/eventloop.js:594
throw error;
^

Error: Timeout: did not get to load all resources on this page
at Timeout.timeout (/usr/local/lib/node_modules/kludgy/node_modules/zombie/lib/eventloop.js:601:38)
at ontimeout (timers.js:471:11)
at tryOnTimeout (timers.js:306:5)
at Timer.listOnTimeout (timers.js:266:5)
Error: Must specify panoID with --id option
at Promise (/usr/local/lib/node_modules/kludgy/node_modules/extract-streetview/index.js:42:34)
at parseLocation (/usr/local/lib/node_modules/kludgy/node_modules/extract-streetview/index.js:39:10)
at Object. (/usr/local/lib/node_modules/kludgy/node_modules/extract-streetview/index.js:34:1)
at Module._compile (module.js:413:34)
at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/kludgy/node_modules/devtool/lib/require-hook.js:32:14)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at EventEmitter. (/usr/local/lib/node_modules/kludgy/node_modules/devtool/lib/preload.js:78:16)
Error: Format error in file - /Users/djbeeker/Desktop/.jpg

In case this is useful. Probably something to do with my upgrade to High Sierra between now and the last time it was working for me.

Document that save location must be absolute

I thought I implemented tilde expansion, but it looks like I did not.

Though, IIRC, I may have skipped tilde expansion for the sake of simplicity.

Either add tilde expansion for the image save location option or just make sure to document that the path to the save folder must be an absolute system path.

I think life would be easier to just document root path as the code has multiple entry points, not all of them are through node (which would make tilde expansion easy), so I'd rather not have to write code for each entry point (ok, it would just be node.js or shell, but still, seems like documenting root path is a requirement is best).

Chrome headless

$ chrome --headless --disable-gpu --repl http://mky.io/random-street-coords/
[0707/092640.194270:INFO:headless_shell.cc(278)] Type a Javascript expression to evaluate or "quit" to exit.
>>> window.COORDS
{"result":{"type":"string","value":"{\"lat\":69.56685225156927,\"lng\":118.69960863143206}"}}

better name

Need a wayyyyyy better repo name and CLI name to match.

Generate internet shortcuts

That points to the pano world view, or pano itself, for example:

[InternetShortcut]
URL=https://maps.google.com/?q=-33.67614817925245,-69.01404288410123&ll=-33.67614817925245,-69.01404288410123&z=0

Put that in folder next to images, make it’s file name be <image_key>.url.

Ok, create one for earth view, one for street view and one for the user’s homepage (if not Google official).

...... 2> /dev/null

Got this today when entering in an invalid Google Maps Key:

$ kludgy "xxxxxxxxx"
Invalid TAG name: 6.395677543337092
Invalid TAG name: 6.395677543337092
Invalid TAG name: 6.395677543337092
Warning: Can't convert GPS:GPSLatitudeRef (not in PrintConv)
Ignored superfluous tag names or invalid options: -6.395677543337092 ...
Error: File not found - Maps
Error: File not found - API
Error: File not found - error:
Error: File not found - InvalidKeyMapError
Error: File not found - https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error
Error: File not found - Google
Error: File not found - Maps
Error: File not found - API
Error: File not found - error:
Error: File not found - InvalidKeyMapError
Error: File not found - https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error
Error: File not found - Maps
Error: File not found - API
Error: File not found - error:
Error: File not found - InvalidKeyMapError
Error: File not found - https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error
Error: File not found - Google
Error: File not found - Maps
Error: File not found - API
Error: File not found - error:
Error: File not found - InvalidKeyMapError
Error: File not found - https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error
Error: File not found - Maps
Error: File not found - API
Error: File not found - error:
Error: File not found - InvalidKeyMapError
Error: File not found - https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error
Error: File not found - Google
Error: File not found - Maps
Error: File not found - API
Error: File not found - error:
Error: File not found - InvalidKeyMapError
Error: File not found - https://developers.google.com/maps/documentation/javascript/error-messages#invalid-key-map-error

I think the "Invalid TAG name" was due to the output from the Google Maps HTML scraping (probably a console message that got output and passed to shell scripts).

Thinking if this happens more often, send the output to 2> /dev/null.

Provide some sort of feedback as it is looking for a pano

Currently, when executing this code via command line, there's no feedback.

I think it would be nice to see something … I'd like to know if it's working, or what it's waiting on. Some sort of "checking .... No pano found (lat/lon coords) ... Trying again ..." etc.

Error: Timeout: did not get to load all resources on this page

Just got this the other day:

$ kludgy "xxxxxxxxxxxxxxxxxxxxxxxx"
/usr/local/lib/node_modules/kludgy/node_modules/zombie/lib/eventloop.js:594
            throw error;
            ^

Error: Timeout: did not get to load all resources on this page
    at Timeout.timeout (/usr/local/lib/node_modules/kludgy/node_modules/zombie/lib/eventloop.js:601:38)
    at ontimeout (timers.js:478:11)
    at tryOnTimeout (timers.js:302:5)
    at Timer.listOnTimeout (timers.js:262:5)
Error: Must specify panoID with --id option
    at Promise (/usr/local/lib/node_modules/kludgy/node_modules/extract-streetview/index.js:42:34)
    at parseLocation (/usr/local/lib/node_modules/kludgy/node_modules/extract-streetview/index.js:39:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/kludgy/node_modules/extract-streetview/index.js:34:1)
    at Module._compile (module.js:413:34)
    at Object.devtoolCompileModule [as .js] (/usr/local/lib/node_modules/kludgy/node_modules/devtool/lib/require-hook.js:32:14)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at EventEmitter.<anonymous> (/usr/local/lib/node_modules/kludgy/node_modules/devtool/lib/preload.js:78:16)
Error: Format error in file - /usr/local/lib/node_modules/kludgy/panos/.jpg

I have yet to reproduce.

Related: #30, because it might be nice to see where it gets stuck. So, like a verbose mode.

Also, setting a timeout that is like 30 seconds could be nice. IIRC, this took a while to return.

No worky when installed globally

It's because the bin.js does not know where to run npm start from.

Here's is a possible fix:

let cwd = path.dirname(fs.realpathSync(process.argv[1]));
exec(`cd "${cwd}" && npm start -- "${helpers.argv(0)}" "${helpers.argv(1)}"`);

Seems slightly hacky though. Need to figure out if this is the best way to call npm start from a bin script?

Move code from ...

Move from here:

https://github.com/mhulse/rando

To this repo.

#!/usr/bin/env node
// jshint esversion:6

//const yargs = require('yargs');
const zombie = require('zombie');
//const pkg = require('../package.json');

//let options = {};

// function ddd(file) {
// 	
// 	try {
// 		
// 		// Run Chrome as background process
// 		// https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
// 		// --disable-gpu currently required, see link above
// 		let child = spawn('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', ['--headless', '--remote-debugging-port=9222', '--disable-gpu'], {
// 			encoding: 'utf8',
// 			detached: true,
// 		});
// 		child.unref();
// 		
// 		console.log('stdout here: \n' + child.stdout);
// 		
// 	} catch(error) {
// 		
// 		console.log('Could not run Chrome as a background process!')
// 		
// 	}
// 	
// }

// function startApp() {
// 
// 	// https://medium.com/@dschnr/using-headless-chrome-as-an-automated-screenshot-tool-4b07dffba79a
// 	// https://objectpartners.com/2017/04/13/how-to-install-and-use-headless-chrome-on-osx/
// 
// 	// $ chrome --headless --disable-gpu --repl http://mky.io/random-street-coords/
// 	// [0707/092640.194270:INFO:headless_shell.cc(278)] Type a Javascript expression to evaluate or "quit" to exit.
// 	// >>> window.COORDS
// 	//{"result":{"type":"string","value":"{\"lat\":69.56685225156927,\"lng\":118.69960863143206}"}}
// 
// 	CDP(client => {
// 		// extract domains
// 		const { Network, Page } = client;
// 		// setup handlers
// 		Network.requestWillBeSent(params => {
// 			console.log(params.request.url);
// 		});
// 		Page.loadEventFired(() => {
// 			client.close();
// 		});
// 		// enable events then start!
// 		Promise.all([Network.enable(), Page.enable()])
// 			.then(() => {
// 				return Page.navigate({ url: "https://github.com" });
// 			})
// 			.catch(err => {
// 				console.error(err);
// 				client.close();
// 			});
// 	}).on('error', error => {
// 		// cannot connect to the remote endpoint
// 		console.error(error);
// 	});
// 
// }

async function getOptions() {

	// let argv = yargs
	// 	.version(pkg.version)
	// 	.usage(`Usage: ddddd`)
	// 	.alias('h', 'help')
	// 	.help('h', 'Show help.')
	// 	.argv;

	//startApp();
	
	//ddd();

	// const browser = new chrome({
	// 	headless: true,
	// 	repl: true
	// });
	// await browser.init();
	// await browser.goTo('https://google.com/');
	// const result = await browser.evaluate(() => document.title)
	// console.log(result)
	// browser.onConsole(msg => {
	// 	console.log('dddd');
	// })
	// await browser.close(true)
	
}

//getOptions();


browser = new zombie({
	debug: false,
	runScripts: true,
	loadCSS: false
});
browser.visit('http://mky.io/random-street-coords/', function(error) {
	if (error) {
		throw error;
	}
	browser.wait().then(() => {
		coords = JSON.parse(browser.window.COORDS);
		console.log(`${coords.lat},${coords.lng}`);
	});
});

Convert CLI args to key/value

So, like:

$ kludgy key=dfjslkfjfldskjfslkjfldjfld tiny path=/blah/

Also, why did I make so much use of shell scripting? I forget the reasoning here. Kinda thinking it might be more maintainable to try refactor as node.

Document cron job

Work in progress:

# Check for existing cron:
$ crontab -l
# If so, back up existing crontab:
$ crontab -l > /Users/mhulse/Desktop/crontab.txt
# ...

Contents of crontab.txt:

*/10 * * * * kludgy "AIzaSyDNuylDKnjnYY46zkORPEt2-g4HK3O6wnw" "/Users/mhulse/Desktop/"  >> /Users/mhulse/Desktop/log.txt 2>&1

Restrict to an area?

From @beekman:

Might be cool to think of other ways to restrict the pool
To filter
Like v3 could maybe let you choose a continent
Or a band of coordinates
So equator only
Etc

Awesome idea.

Related: mhulse/rand-land-coords#5

So, should there be an option for someone to specify their own rand-land-coord image? Or, perhaps, just set an area and pass that along to rand-land-coords? So, should rand-land-coords restrict to an area?

See: mhulse/rand-land-coords#6

top.html usage

I just did not have time to get a variable via comment line in there to replace the top.html bit.

Show example of how to use.

Maybe simply touching a new file with a string:

$ echo "<google maps tag with key>" >> /path/to/top.html

Feature to save to iPhoto album

From @beekman:

Another thought-- could it save to a Photos album?
If so that option might make it even easier on them
... lots of apps will let you save directly to an album (usually titled with the app name)
So you end up with a collection of all the images in a place that can be backed up/shared/merged in icloud

Great idea!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.