<commit_before>import os
import glob
import re
from flask import Flask, request, jsonify, abort, json
#import psycopg2, psycopg2.extras
import msc_apps

#data_dir_root = os.environ.get('DATADIR')

app = Flask(__name__)
app.debug = True

#TODO COnversion
@app.route('/properties')
def properties():
  ROWS=dbSelect("select * from smartproperties")

  def dehexify(hex_str):
      temp_str=[]
      for let in hex_str:
          if ord(let) < 128:
              temp_str.append(let)
          else:
              temp_str.append('?')
      return ''.join(temp_str)

  response = []
  for sprow in ROWS:
      res = {
          'currencyID': sprow[1],
          'name': dehexify(sprow[-1]['name']) 
      }
      response.append(res)

  json_response = json.dumps( sorted(response, key=lambda x:  int(x['currencyID']) ))
  return json_response

@app.route('/addresses')
def addresses():
  currency_id = request.args.get('currency_id')
  response = []

  currency_id = re.sub(r'\D+', '', currency_id) #check alphanumeric
  ROWS=dbSelect("select address,balanceavailable,balancereserved,sp.propertytype from addressbalances ab, smartproperties sp "
                "where ab.propertyid=sp.propertyid and sp.propertyid=%s",[currency_id])

  for addrrow in ROWS:
      res = {
          'address': addrrow[0]
      }
      divisible=addrrow[3]

      if currency_id == '0': #BTC
        res['balance'] = ('%.8f' % float(addrrow[1])).rstrip('0').rstrip('.')
        response.append(res)
      else:
        if divisible:
          res['balance'] = ('%.8f' % float(addrrow[1]/100000000)).rstrip('0').rstrip('.')
          res['reserved_balance'] = ('%.8f' % float(addrrow[2]/100000000)).rstrip('0').rstrip('.')
        else:
          res['balance'] = ('%.8f' % float(addrrow[1])).rstrip('0').rstrip('.')
          res['reserved_balance'] = ('%.8f' % float(addrrow[2])).rstrip('0').rstrip('.')
        response.append(res)

  json_response = json.dumps(response)
  return json_response


@app.route('/transactions/<address>')
def transactions(address=None):
  currency_id = request.args.get('currency_id')

  print address, currency_id

  if address == None:
    abort(400)

  currency_id = re.sub(r'\D+', '', currency_id) #check alphanumeric

  ROWS=dbSelect("select * from addressesintxs a, transactions t where a.address=%s  and a.txdbserialnum = t.txdbserialnum and a.propertyid=%s",
                (address, currency_id))

  transactions = []
  for txrow in ROWS:
      transactions.append(txrow[9])

  return jsonify({ 'address': address, 'transactions': transactions })

<commit_msg>fix import directive<commit_after>import os
import glob
import re
from flask import Flask, request, jsonify, abort, json
#import psycopg2, psycopg2.extras
from msc_apps import *

#data_dir_root = os.environ.get('DATADIR')

app = Flask(__name__)
app.debug = True

#TODO COnversion
@app.route('/properties')
def properties():
  ROWS=dbSelect("select * from smartproperties")

  def dehexify(hex_str):
      temp_str=[]
      for let in hex_str:
          if ord(let) < 128:
              temp_str.append(let)
          else:
              temp_str.append('?')
      return ''.join(temp_str)

  response = []
  for sprow in ROWS:
      res = {
          'currencyID': sprow[1],
          'name': dehexify(sprow[-1]['name']) 
      }
      response.append(res)

  json_response = json.dumps( sorted(response, key=lambda x:  int(x['currencyID']) ))
  return json_response

@app.route('/addresses')
def addresses():
  currency_id = request.args.get('currency_id')
  response = []

  currency_id = re.sub(r'\D+', '', currency_id) #check alphanumeric
  ROWS=dbSelect("select address,balanceavailable,balancereserved,sp.propertytype from addressbalances ab, smartproperties sp "
                "where ab.propertyid=sp.propertyid and sp.propertyid=%s",[currency_id])

  for addrrow in ROWS:
      res = {
          'address': addrrow[0]
      }
      divisible=addrrow[3]

      if currency_id == '0': #BTC
        res['balance'] = ('%.8f' % float(addrrow[1])).rstrip('0').rstrip('.')
        response.append(res)
      else:
        if divisible:
          res['balance'] = ('%.8f' % float(addrrow[1]/100000000)).rstrip('0').rstrip('.')
          res['reserved_balance'] = ('%.8f' % float(addrrow[2]/100000000)).rstrip('0').rstrip('.')
        else:
          res['balance'] = ('%.8f' % float(addrrow[1])).rstrip('0').rstrip('.')
          res['reserved_balance'] = ('%.8f' % float(addrrow[2])).rstrip('0').rstrip('.')
        response.append(res)

  json_response = json.dumps(response)
  return json_response


@app.route('/transactions/<address>')
def transactions(address=None):
  currency_id = request.args.get('currency_id')

  print address, currency_id

  if address == None:
    abort(400)

  currency_id = re.sub(r'\D+', '', currency_id) #check alphanumeric

  ROWS=dbSelect("select * from addressesintxs a, transactions t where a.address=%s  and a.txdbserialnum = t.txdbserialnum and a.propertyid=%s",
                (address, currency_id))

  transactions = []
  for txrow in ROWS:
      transactions.append(txrow[9])

  return jsonify({ 'address': address, 'transactions': transactions })


{'fraction_non_alphanumeric': 0.1589416763229046, 'fraction_numerical': 0.018153727307840865, 'mean_word_length': 3.283705541770058, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '322091', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1713, 'n_words': 343}