def __init__(self, in_user_mode=True): """Connect to the Dropbox servers so that files can be uploaded""" self.m = Message(in_user_mode=in_user_mode) session = DropboxSession(API_KEY, API_SECRET, self.ACCESS_TYPE) token_file = PyJson(TOKEN_PATH) token = token_file.doc # If there is a token saved, that can be used to connect with Dropbox if 'key' in token and 'secret' in token: # Read the token and authenticate the session with it session.set_token(token['key'], token['secret']) # Otherwise it is necessary to authenticate for the first time else: # Request an access token request_token = session.obtain_request_token() url = session.build_authorize_url(request_token) # Open the authentication page in the user's browser and wait for them to accept webbrowser.open(url, new=2) print("Press enter once you have authorised the app in your browser") input() # Get a new access token from the authenticated session # This will fail if the user didn't visit the above URL and press 'Allow' try: access_token = session.obtain_access_token(request_token) except Exception as error: if DEBUG: print(error) print("You didn't authorise the app, or something else went wrong") exit(1) # Save the access token to a file so that authentication is not needed next time the app is run token_file.add('key', access_token.key) token_file.add('secret', access_token.secret) token_file.save() # Create a Dropbox client from the session client = DropboxClient(session) self.client = client
# Copyright 2021 EMQ Technologies Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License 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. from ekuiper import plugin, PluginConfig from print import PrintSink from pyjson import PyJson from revert import revertIns if __name__ == '__main__': c = PluginConfig("pysam", {"pyjson": lambda: PyJson()}, {"print": lambda: PrintSink()}, {"revert": lambda: revertIns}) plugin.start(c)
def __init__(self): self.history_file = PyJson(HISTORY_PATH, base={'history': []}) self.history = self.history_file.doc['history']