# -*- coding: UTF-8 -*-
# 获得编码格式
import chardet
# 读取和打开url
from urllib import request
import requests
import os
# 关闭https证书验证
import ssl
import time
import json
import pymysql
import time
import traceback
from random import choice
from bs4 import BeautifulSoup
import phoenixdb
import phoenixdb.cursor
# 数据库封装方法
from pymongo import MongoClient
if __name__ == '__main__':
myclient = MongoClient("mongodb://localhost:27017/")
mydb = myclient["aisdb"]
my_set = mydb.shipinfos
database_url = 'http://ambari1:8765'
conn = phoenixdb.connect(database_url, autocommit=True)
cursor = conn.cursor()
for ship in my_set.find():
sql = "upsert into shipinfo VALUES ('%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')" % \
(str(ship["_id"]),str(ship["destination"]),str(ship["length"]),str(ship["imo"]),str(ship["shipName"]),str(ship["shipNameNoSpace"]),
str(ship["callSign"]), str(ship["breath"]),str(ship["eta"]),str(ship["draught"]),str(ship["shipType"]),str(ship["sourcetype"]),str(ship["destinationNoSpace"]))
print(sql)
cursor.execute(sql)