
Plugins para cree.py
Plugins para cree.py
A arquitetura do cree.py permite múltiplas fontes definidas pelo usuário para informações de geolocalização. Essas fontes são definidas como plugins e podem ser instaladas no creepy copiando-as para a pasta de plugins no diretório de instalação.
Crie um pull request para um novo plugin se quiser compartilhá-lo com outros usuários, e eu verificarei e mesclarei no repositório
Plugins para o creepy precisam de pelo menos 3 arquivos :
A arquitetura do módulo é construída com a ajuda do yapsy (http://yapsy.sourceforge.net.).
Inclua as seguintes informações no seu arquivo plugin_name.yapsy-plugin
[Core]
Name = Plugin Name
Module = plugin_name
[Documentation]
Author =
Version =
Website =
Description =
O arquivo python que contém a lógica do plugin. Ele precisa estender a classe InputPugin e implementar, no mínimo, uma série de métodos. Portanto, você deve defini-lo como abaixo (veja os comentários inline):
from models.InputPlugin import InputPlugin
class PluginName(InputPlugin):
name="plugin_name"
'''
If your plugin configuration needs to invoke a wizard
(for example for oAuth authorization) this must be set to true
'''
hasWizard=True
def searchForTargets(self, search_term):
'''
Parameters
----------
search_term : str
The search term that the user entered in the New Project wizard. It could be a mail, id,
username, full name, it is the plugin's responsibility to differentiate between
different types if needed
Accepts a string parameter from the user and performs a search in the respective service/source
for identifying possible targets to be included in the process.
Returns a list of dictionaries, one for each identified target or an empty list if no results were
found. The dictionaries need to include the following keys :
target = {'pluginName':'Plugin Name',
'targetUserid' : 'The userid of the target in the service/source',
'targetUsername' : 'The username of the target in the service/source',
'targetPicture' : 'the filename of the profile picture of the target ( profile_pic_targetUserid )',
'targetFullname' : 'The full name of the target'}
'''
your_code_here()
def runConfigWizard(self):
'''
If your plugin's configuration needs a wizard, create it here. You need to save the configuration
values to the plugin's config file before returning.
Access to the plugin configuration file is offered through the
readConfiguration(category) method that is inhereted from from the InputPlugin. This returns a tuple
config,options where
-- config is the ConfigObj file that you can use to save the configuration by
calling it's write() method
-- options is the dictionary containing your configuration category options.
'''
def isConfigured(self):
'''
Returns a tuple. The first element is True or False, depending if the plugin is configured or not. The second
element contains an optional message for the user
'''
def returnLocations(self, target, search_params):
'''
Parameters
----------
target : dict
search_params : dict
Returns a list of location dictionaries (or empty list if no locations were found) for the specified
target using the specified search parameters
Target is a dictionary with information as defined in searchForTargets and search_params is a
dictionary with search parameters that you would have defined as available in your configuration file
(see plugin_name.conf below).
The location dictionary needs to contain the following keys :
loc = {'plugin' : 'twitter'
'context' : 'Context of the location"
'infowindow' : "HTML with information in the location to be shown in the infoWindow on the map"
'date' : 'a datetime.datetime object with information on when the gelocation was created'
'lat' : 'latitude of the location'
'lon' : 'longitude of the location'
'shortName' : 'short name describing the location, empty string if not available'}
'''
Se o seu plugin precisar de módulos externos que não são distribuídos com o Python, você precisa declarar isso explicitamente para os usuários, preferencialmente com instruções sobre como instalar as dependências em cada plataforma.
O arquivo contém todas as suas opções de configuração e deve ter as seguintes seções (algumas ou todas podem estar vazias):
[string_options]
key1 = value
[boolean_options]
key2 = True
key3 = False
[search_string_options]
key4 = some value
[search_boolean_options]
key5 = True
As opções string_options e boolean_options aparecerão como opções de configuração na caixa de diálogo de Configuração do Plugin.
As opções search_string_options e search_boolean_options estarão disponíveis como opções de pesquisa no Assistente de Novo Projeto.
Se você precisar mascarar um valor na GUI (ou seja, senhas, tokens de acesso etc.), prefixe a chave com hidden_ e o cree.py cuidará disso.
Se você quiser que suas opções de configuração tenham um nome mais amigável na GUI, você pode fornecer rótulos para elas aqui. Por exemplo, usando o arquivo conf acima como referência, seu arquivo plugin_name.labels poderia ser assim:
[labels]
key1 = Label For Key 1
key2 = Label For Key 2
key3 = Label For Key 3
key4 = Label For Key 4
key5 = Label For Key 5
Se você não especificar um rótulo para uma chave, a chave será exibida na GUI.
Reúna todos os arquivos acima em uma pasta chamada plugin_name e copie a pasta para o diretório plugins do aplicativo instalado. Simples assim!