Last active
July 29, 2016 19:51
-
-
Save rubyu/2d1647cfe960ee36e98d3b6c52650a30 to your computer and use it in GitHub Desktop.
ファイル名でググッてFirefoxで開く
This file contains 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
# -*- coding: utf-8 -*- | |
''' | |
Created on 2015/05/08 | |
@author: user | |
''' | |
import sys | |
import os | |
import urllib | |
import subprocess | |
firefox = "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" | |
def main(): | |
if len(sys.argv) == 1: | |
sys.exit("target path is not given") | |
for arg in sys.argv[1:]: | |
path = unicode(arg, "cp932") | |
name = os.path.basename(path) | |
phrase = os.path.splitext(name)[0] | |
escaped_phrase = urllib.quote_plus(phrase.encode("utf-8")) | |
query_string = "https://www.google.co.jp/search?q=" + escaped_phrase + "^&ie=utf-8^&oe=utf-8^&hl=ja" | |
print query_string | |
subprocess.call([firefox, query_string], shell=True) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment