Beispiel #1
0
def tip(msg, user_id):
    """
    either tips a person a random amount or tips them x seckc coins
    :param msg: <person recieving tip> <random x y | x>
    :param user_id: the id of the user doing the tipping
    """
    msg = parse(msg)
    if msg is None: #no target user
        return ("error", "")
    form = {
        'user_id': user_id,
        'target_user': msg[0],
        'balance': get_balance(user_id),
        'amount': set_amount(msg[1:]),
    }
    if form["amount"] is None: #we recieved a non-int
        return ("error", "")
    form['transaction'] = make_transaction(user_id, form['target_user'], form['amount'])
    form['user_address'] = get_address(user_id)
    form['target_user_address'] = get_address(form['target_user'])
    form['user_balance'] = get_balance(user_id)
    form['target_user_balance'] = get_balance(form['target_user'])
    ############# fill out data
    tip_attachment = json.dumps([{
        "fallback":"<@{user_id}> tipped <@{target_user}> {amount} :SKC:".format(**form),
        "color": "good",
        "author_name": "SecKCoin Bank and Trust",
        "footer": "Please note: Transactions require at least one block confirmation in order to appear (Up to 5 minutes)",
        "fields": [
            {
                "title": ":skc: Transaction Hash:",
                "value": form['transaction'],
                "short": False
            },
            {
                "title": "From: ",
                "value": """<@{user_id}>
<https://seckco.in/address/{user_address}|{user_address}>
Current Balance: {user_balance}""".format(**form),
                "short": True
            },
            {
                "title": "To: ",
                "value": """<@{target_user}>
<https://seckco.in/address/{target_user_address}|{target_user_address}>
Current Balance: {target_user_balance}""".format(**form),
                "short": True
            }
        ]}], indent=4)

    currency_icon = ":skc:"
    tip_pretext = ":money_with_wings:"
    tip_posttext = " (View transaction on <https://seckco.in/tx/%s|https://seckco.in>)" % form['transaction']
    tip_message = "%s <@%s> => <@%s> %s %s %s" % (tip_pretext, user_id,
                                                  form['target_user'], form['amount'],
                                                  currency_icon, tip_posttext)

    return (tip_message, tip_attachment)
Beispiel #2
0
    def __init__(self):
        super(Bus, self).__init__()
        self.__dbusconn = dbus.connection.Connection(common.get_address())
        self.__dbus = self.__dbusconn.get_object(dbus.BUS_DAEMON_NAME,
                                                 dbus.BUS_DAEMON_PATH)
        self.__unique_name = self.hello()
        self.__ibus = self.__dbusconn.get_object(common.IBUS_SERVICE_IBUS,
                                                 common.IBUS_PATH_IBUS)

        self.__dbusconn.call_on_disconnection(self.__dbusconn_disconnected_cb)
Beispiel #3
0
    def __init__(self):
        super(Bus, self).__init__()
        self.__dbusconn = dbus.connection.Connection(common.get_address())
        self.__dbus = self.__dbusconn.get_object(dbus.BUS_DAEMON_NAME,
                                                 dbus.BUS_DAEMON_PATH)
        self.__unique_name = self.hello()
        self.__ibus = self.__dbusconn.get_object(common.IBUS_SERVICE_IBUS,
                                                 common.IBUS_PATH_IBUS)
        self.__ibus.connect_to_signal("RegistryChanged",
                                      self.__registry_changed_cb)

        self.__dbusconn.call_on_disconnection(self.__dbusconn_disconnected_cb)
Beispiel #4
0
    def __init__(self):
        super(Bus, self).__init__()
        self.__dbusconn = dbus.connection.Connection(common.get_address())
        _dbus = self.__dbusconn.get_object(dbus.BUS_DAEMON_NAME,
                                           dbus.BUS_DAEMON_PATH)
        self.__dbus = dbus.Interface (_dbus, dbus_interface="org.freedesktop.DBus")
        self.__unique_name = self.hello()

        _ibus = self.__dbusconn.get_object(common.IBUS_SERVICE_IBUS,
                                           common.IBUS_PATH_IBUS)
        self.__ibus = dbus.Interface (_ibus, dbus_interface='org.freedesktop.IBus')
        self.__ibus.connect_to_signal("RegistryChanged", self.__registry_changed_cb)

        self.__dbusconn.call_on_disconnection(self.__dbusconn_disconnected_cb)
Beispiel #5
0
    def __init__(self):
        super(Bus, self).__init__()
        self.__dbusconn = dbus.connection.Connection(common.get_address())
        _dbus = self.__dbusconn.get_object(dbus.BUS_DAEMON_NAME,
                                           dbus.BUS_DAEMON_PATH)
        self.__dbus = dbus.Interface (_dbus, dbus_interface="org.freedesktop.DBus")
        self.__unique_name = self.hello()

        _ibus = self.__dbusconn.get_object(common.IBUS_SERVICE_IBUS,
                                           common.IBUS_PATH_IBUS)
        self.__ibus = dbus.Interface (_ibus, dbus_interface='org.freedesktop.IBus')
        self.__ibus.connect_to_signal("RegistryChanged", self.__registry_changed_cb)

        self.__dbusconn.call_on_disconnection(self.__dbusconn_disconnected_cb)
Beispiel #6
0
def deposit(msg, user_id):
    """
    returns user address
    :param msg: msg - unused - should be blank
    :user_id: user's id - used to get the wallet address and for flavor text
    """
    form = {
        'user_id': user_id,
        'user_address': get_address(user_id)
    }
    deposit_message = "<@{user_id}> your :skc: address is: {user_address}".format(**form)
    deposit_attachment = json.dumps(
        [{"fallback": "https://seckco.in/qr/{user_address}".format(**form),
          "color" : "good",
          "author_name" : "SecKCoin Bank and Trust",
          "image_url" : "https://seckco.in/qr/{user_address}".format(**form),
         }])
    return (deposit_message,
            deposit_attachment)
Beispiel #7
0
 def get_address(self):
     return common.get_address()
Beispiel #8
0
 def get_address(self):
     return common.get_address()
    def create_patient(self, country, du, lang, patient, party, subdivision,
                       contact):
        '''Create the patient record

            (better structure? better way to import models?)'''

        #Find language (or not!)
        if self.models.get('lang'):
            self.models['party']['lang'] = None
            comm = find_record(lang, [[
                'OR',
                [('code', 'like', '{0}%'.format(self.models['lang'].get(
                    'code', None)))],
                [('name', 'ilike', '%{0}%'.format(self.models['lang'].get(
                    'name', None)))]
            ]])
            if comm:
                self.models['party']['lang'] = comm

        #Find du (or not!)
        #TODO Shared addresses (apartments, etc.)
        if self.models.get('du'):
            d = find_record(du, [('name', '=', self.models['du'].get(
                'name', -1))])  # fail better
            if d:
                self.models['party']['du'] = d.id
            else:
                #This uses Nominatim to give complete address details
                query = ', '.join([
                    str(v) for k, v in self.models['du'].items() if k in [
                        'address_street_number', 'address_street',
                        'address_city'
                    ]
                ])
                query = ', '.join([
                    query, self.models['subdivision'] or '',
                    self.models['country'] or ''
                ])
                details = get_address(query)
                if details:
                    pass

                # Find subdivision (or not!)
                if self.models['subdivision']:
                    self.models['du']['address_subdivision'] = None
                    s = find_record(subdivision, [[
                        'OR',
                        [('code', 'ilike', '%{0}%'.format(
                            self.models['subdivision']))],
                        [('name', 'ilike', '%{0}%'.format(
                            self.models['subdivision']))]
                    ]])
                    if s:
                        self.models['du']['address_subdivision'] = s.id
                        self.models['du']['address_country'] = s.country.id

                # Find country (or not!)
                if self.models['du'].get('address_country', None):
                    self.models['du']['address_country'] = None
                    if self.models['country']:
                        co = find_record(country, [[
                            'OR',
                            [('code', 'ilike', '%{0}%'.format(
                                self.models['country']))],
                            [('name', 'ilike', '%{0}%'.format(
                                self.models['country']))]
                        ]])
                        if co:
                            self.models['du']['address_country'] = co.id

                d = du.create([self.models['du']])[0]
                self.models['party']['du'] = d

        n = party.create([self.models['party']])[0]

        if self.models.get('contact_mechanism'):
            for c in self.models['contact_mechanism']:
                if c['value'] is not None:
                    c['party'] = n
                    contact.create([c])

        self.models['patient']['name'] = n
        p = patient.create([self.models['patient']])[0]
        return p