源碼傳送門
環境準備
下面的兩個第三方模塊都可以直接通過pip快速安裝,這里使用py36作為運行環境。
python3.6 requests exifread思路
基礎知識
下面是現今相片中會存在與GPS相關的關鍵字,大牛亦可一比帶過~ [參考]
{ "GPSVersionID": "GPS版本", "GPSLatitudeRef": "南北緯", "GPSLatitude": "緯度", "GPSLongitudeRef": "東西經", "GPSLongitude": "經度", "GPSAltitudeRef": "海拔參照值", "GPSAltitude": "海拔", "GPSTimeStamp": "GPS時間戳", "GPSSatellites": "測量的衛星", "GPSStatus": "接收器狀態", "GPSMeasureMode": "測量模式", "GPSDOP": "測量精度", "GPSSpeedRef": "速度單位", "GPSSpeed": "GPS接收器速度", "GPSTrackRef": "移動方位參照", "GPSTrack": "移動方位", "GPSImgDirectionRef": "圖像方位參照", "GPSImgDirection": "圖像方位", "GPSMapDatum": "地理測量資料", "GPSDestLatitudeRef": "目標緯度參照", "GPSDestLatitude": "目標緯度", "GPSDestLongitudeRef": "目標經度參照", "GPSDestLongitude": "目標經度", "GPSDestBearingRef": "目標方位參照", "GPSDestBearing": "目標方位", "GPSDestDistanceRef": "目標距離參照", "GPSDestDistance": "目標距離", "GPSProcessingMethod": "GPS處理方法名", "GPSAreaInformation": "GPS區功能變數名", "GPSDateStamp": "GPS日期", "GPSDifferential": "GPS修正"}
初始化
考慮到exifread的模塊中有大量的logging輸出,這里將它的level級別調到最高。 然后下邊的KEY是某站在高德地圖API的時候遺留下來的 我也很尷尬。。就當福利了
import osimport timeimport jsonimport randomimport loggingimport requestsimport exifreadlogging.basicConfig(level=logging.CRITICAL)KEY = "169d2dd7829fe45690fabec812d05bc3"
主邏輯函數
def main(): # 預設后綴列表 types = ["bmp", "jpg", "tiff", "gif", "png"] #結果數據集合 picex = [] # 文件存儲路徑 saves = "$" + input("| SavePath: ").strip() # 文件搜索路徑 并遍歷所有文件返回文件路徑列表 pools = jpgwalk(input("| FindPath: "), types) #存儲目錄 savep = "%s/%s" % (os.getcwd().replace("http://", "/"), saves) if savep in pools: pools.remove(savep) # 遍歷數據集并獲取exif信息 for path in pools: res = getEXIF(path) if res: picex.append(res) # 結果報告 print("| Result %s" % len(picex)) # 如果存在結果 保存結果到json并講相關圖片復制到該目錄下 if picex: #創建目錄 if not os.path.exists(saves): os.mkdir(saves) #生成一個4格縮進的json文件 with open("%s/%s.json" % (saves, saves), "wb") as f: f.write(json.dumps(picex, ensure_ascii=False, indent=4).encode("utf8")) #copy圖像到該目錄 for item in picex: source_path = item["Filename"] with open("%s/%s" % (saves, source_path.split("/")[-1]), "wb") as f_in: with open(source_path, "rb") as f_out: f_in.write(f_out.read())
新聞熱點
疑難解答