class StoryAttachment():
    def __init__(self):
        self.reg = r'UI(\d{6})'
        self.restTemplate = RestTemplate()
        self.fileHelper = FileHelper()
        self.attachmentApi = "http://tracker.paas.cmbchina.cn/tracker/attachment/queryAttachFile?referenceId={storyId}&type=story"
        # self.attachmentApi = "http://*****:*****@' + self.fileHelper.wx_file_type(path) + '@' + path
        except Exception as e:
            print e.message
            chat.send(u'附件获取出错')
            pass
        else:
            try:
                chat.send(content)
            except ResponseError as e:
                print(e.err_code, e.err_msg)
                chat.send(u'附件发送失败!!!')
                pass
            finally:
                self.fileHelper.delete(path)
예제 #2
0
	def __init__(self, Host, User, Pwd, login_type, params):
		self._Host = Host;
		self._User = User;
		self._Pwd = Pwd;
		self._login_type = login_type;
		self._params = params;
		self._trans = "";
		self._insertCode = InsertCode();
		self._fileHelper = FileHelper();
예제 #3
0
    def __init__(self, parent, title):
        super(MainWindow, self).__init__(parent, title=title, size=(800, 300))
        self.x = 0
        self.y = 0
        self.z = 0
        self.yaw = 0
        self.connected = False
        self.bm = wx.Bitmap(FileHelper.getPath("gfx/fh4map_main.jpg"))
        img = wx.Image(
            FileHelper.getPath("gfx/fh4map_main.jpg")
        )  # need it as Image too very temporarely, just to fetch its initial size.
        self.rawImgW = img.Width
        self.rawImgH = img.Height
        img.Destroy()
        self.carBm = wx.Bitmap(FileHelper.getPath("gfx/car.png"))
        titleHeight = self.GetRect().height - self.GetClientRect().height
        self.SetSize(
            self.rawImgW / 1.5, self.rawImgH / 1.5 + (titleHeight / 1.5)
        )  # the last part is broken, (not a direct formula, but seems to work on windows at least). It seems to be hard to size the window exactly.

        self.InitUI()
        self.recorder = UdpRecorder(self.udpReceivedData, self.udpTimeout)
예제 #4
0
class PPHelper:
	def __init__(self, Host, User, Pwd, login_type, params):
		self._Host = Host;
		self._User = User;
		self._Pwd = Pwd;
		self._login_type = login_type;
		self._params = params;
		self._trans = "";
		self._insertCode = InsertCode();
		self._fileHelper = FileHelper();

	# init the helper.
	def _initHelper(self):
		if(self._login_type == "FTP"):
			self._trans = FTPHelper(
				host=self._Host,
				user=self._User,
				pwd=self._Pwd);
		else :
			self._trans = SSHHelper(
				host=self._Host,
				user=self._User,
				pwd=self._Pwd);
		return;

        # return the login result.
        # use the ftplib and paramiko.
	def _getLoginResult(self):
		if(self._login_type == "FTP"):
			self._tryLogin = ftplib.FTP(self._Host);
			tmp = self._tryLogin.login(self._User, self._Pwd);
			tmp = tmp.split();

			return True if tmp[0] == '230' else False;

		else:
			self._tryLogin = paramiko.SSHClient();
			self._tryLogin.set_missing_host_key_policy(paramiko.AutoAddPolicy());
			tmp = self._tryLogin.connect(self._Host, 22, self._User, self._Pwd);

			return True if tmp==None else False;

        # close the login connect.
	def _tryLoginClose(self):
		if(self._login_type == "FTP"):
			self._tryLogin.quit();
		else :
			self._tryLogin.close();

		self._tryLogin = "";
		return;

	#check whether the param is worked.
	def checkEnter(self):
		print "We are checking the param, please wait...";

		logging.info("trying to login the server...");

		# mark the succeed or not.
		flag = True;

		try :
			succInfo = "success to login the server.";
			failedInfo = "failed to login the server.";
			flag = self._getLoginResult();

			if(flag == True):
				logging.info(succInfo);
			else :
				logging.info(failedInfo);

			self._tryLoginClose();
		except Exception as e:
			errorInfo = "An exception occured when login the server.";
			logging.info(errorInfo);
			self._tryLoginClose();
			flag = False;

		return flag;

	# the main function. Totally 3 sub functions:
	# 1.Get files from FTP server to local.
	# 2.Insert scripts to local files.
	# 3.Upload files from local to FTP server.
	def InsertToFiles(self, params, path):
		self._initHelper();

		# create a local folder to storage the files.
		_foldername = self._User+(str)(uuid.uuid1());
		localpath = self._fileHelper.createFolder(_foldername + '/' + path);

		logging.info("trying to get server files...");
		# download the files.
		try :
			self._trans.getFiles(params, path, localpath);
			logging.info("succeed to download files.");
		except Exception as e:
			# log the error info.
			logging.info("failed to download files");
			logging.info("error info:"+(str)(e));
			self._fileHelper.deleteFolder(_foldername);
			return -1;

		localfiles = [];
		localfiles = self._fileHelper.GetFiles(localpath);

		logging.info("insert scripts to local files.");
		counts = self._insertCode.insertScripts(self._params, localpath, localfiles);

		logging.info("finished.");

		logging.info("trying to upload files...");

		# only modified files will be uploaded.
		try:
			self._trans.putFiles(path, localpath, counts['files']);
			logging.info("succeed to upload files.");
		except Exception as e:
			# log the error info.
			logging.info("failed to upload files.");
			logging.info("error info:"+(str)(e));
			self._fileHelper.deleteFolder(_foldername);
			return -2;

		# delete the local folder.
		self._fileHelper.deleteFolder(_foldername);
		return 0;

	# get files of the path.
	def getList(self, path):
		self._initHelper();
		resList = self._trans.getList(path);
		return resList;

	# get the init ftp server path.
	def getInitPath(self):
		self._initHelper();
		res = self._trans.getInitPath();
		return res;

        # delete the object.
        def __del__(self):
                del self._trans;
                del self._insertCode;
                del self._fileHelper;
 def __init__(self):
     self.reg = r'UI(\d{6})'
     self.restTemplate = RestTemplate()
     self.fileHelper = FileHelper()
     self.attachmentApi = "http://tracker.paas.cmbchina.cn/tracker/attachment/queryAttachFile?referenceId={storyId}&type=story"
예제 #6
0
    fileHelper.saveConfig(ConfigKeys.LastDestinationPath, path)


def switchPaths():
    helper = uiHelper.sourcePath.get()

    fileHelper.saveConfig(ConfigKeys.LastSourcePath,
                          uiHelper.destinationPath.get())
    uiHelper.sourcePath.set(uiHelper.destinationPath.get())

    uiHelper.destinationPath.set(helper)
    fileHelper.saveConfig(ConfigKeys.LastDestinationPath, helper)


# load last paths
fileHelper = FileHelper()
sourcePath = fileHelper.loadConfig(ConfigKeys.LastSourcePath)
destinationPath = fileHelper.loadConfig(ConfigKeys.LastDestinationPath)

# setup
uiHelper = UiHelper(root=Tk(), fileHelper=fileHelper)
uiHelper.sourcePath = sourcePath
uiHelper.destinationPath = destinationPath

# add ui elements
uiHelper.addLabel("Source Path", row=0, column=0)
uiHelper.addLabel("Destination Path", row=1, column=0)
uiHelper.addTextBoxes()
uiHelper.addButton("Open", row=0, column=10, command=openSourcePath)
uiHelper.addButton("Open", row=1, column=10, command=openDestinationPath)
예제 #7
0
                "[WARNING] The index of elements data is incorrect. Some data maybe lost ..."
            )
            print("Keep running crawler program.")

        # Save data
        cafe_googlemap_info["comments"] = comment_info_list

        # Back to shop information in Google Map
        super().click_ele("button.ozj7Vb3wnYq__action-button-clickable",
                          sleep_time=3)
        return cafe_googlemap_info


if __name__ == '__main__':

    file_helper = FileHelper()

    # Read the basic data (Target coffee shop list)
    cafe_data = file_helper.read_data()
    cafe_ids = [file_helper.get_cafe_id(data) for data in cafe_data]
    cafe_googlemap_url = [
        file_helper.get_googlemap_url(data) for data in cafe_data
    ]
    cafe_googlemap_lat = [
        file_helper.get_googlemap_lat(data) for data in cafe_data
    ]
    cafe_googlemap_lng = [
        file_helper.get_googlemap_lng(data) for data in cafe_data
    ]
    # Start to crawl data
    start_index = 14