Ejemplo n.º 1
0
 def myregister(self):
     print("회원 가입.. ")
     db = DbConnect('192.168.0.68', 'orcl', 'scott', 'tiger', '1521')
     resultLIst = db.execute(
         'select * from emp')  # 리턴값이 리스트인 것을 resultList에 담음
     for x in resultList:
         print(x)
     self.parent.close()
Ejemplo n.º 2
0
	def checkDbConnection(self):
		
		try:
			print 'checking db connection.'
			dbConn = DbConnect()
			#self.__db__ = DbConnect()
			if dbConn.connect() == True:
				self.__db__ = dbConn
			
			self.createTMSDevice()
			
		except Exception, e:
			self.__db__ = None
			print 'Unable to connect to db.. retrying... ' + str(e)
Ejemplo n.º 3
0
class HttpServer:

    app = Flask(__name__)
    dbConnection = None

    def __init__(self):
        self.dbConnection = DbConnect()

    def start(self):
        """Starts the HttpServer"""
        self.app.run()

    @app.route('/')
    def get_home(self):
        return "The server is up! :D"

    @app.route('/api/bill', methods=['POST'])
    def get_bill(self):
        url = request.args.get('url')
        if self.dbConnection.is_bill_exist(url):
            billAnalyser = BillAnalyser(url)
            bill = billAnalyser.getBillSummary()
            self.dbConnection.add_bill(bill)
        return jsonify(bill)
Ejemplo n.º 4
0
 def __init__(self , config):
     self.dbConfig = config
     self.languages = ['java', 'python', 'c#', 'c++', 'php', 'c',
                        'ruby', 'ruby-on-rails', 'javascript', 'jquery',
                         'asp.net', 'objective-c','sql', 'xml', 'perl',
                          'cocoa', 'delphi', 'node.js', 
                          'scala', 'visual-c++']
     self.langString = ''
     for language in self.languages:
         self.langString += "1 as "+ language+", "
     self.langString =self.langString[0:len(self.langString)-2]
     self.postsFields = "id, AcceptedAnswerId, ParentId, CreationDate, Score, ViewCount, Body, OwnerUserId, OwnerDisplayName, LastEditorUserId, LastEditorDisplayName, LastEditDate, LastActivityDate, Title, Tags, AnswerCount, CommentCount, FavouriteCount, ClosedDate, CommunityOwnedDate"
     self.fields = "Tag, PostId, AcceptedAnswerId, ParentId, CreationDate, Score, ViewCount, Body, OwnerUserId, OwnerDisplayName, LastEditorUserId, LastEditorDisplayName, LastEditDate, LastActivityDate, Title, Tags, AnswerCount, CommentCount, FavouriteCount, ClosedDate, CommunityOwnedDate"
     self.valStr=""
     for field in self.fields.split(","):
         self.valStr += "'%s',"
     self.valStr = self.valStr[0:len(self.valStr)-2]
     self.dbConnect =DbConnect(self.dbConfig)
     Session, self.engine  = self.dbConnect.openConnection()
     self.session = Session()
Ejemplo n.º 5
0
class DataLoad():
    
    def __init__(self , config):
        self.dbConfig = config
        self.languages = ['java', 'python', 'c#', 'c++', 'php', 'c',
                           'ruby', 'ruby-on-rails', 'javascript', 'jquery',
                            'asp.net', 'objective-c','sql', 'xml', 'perl',
                             'cocoa', 'delphi', 'node.js', 
                             'scala', 'visual-c++']
        self.langString = ''
        for language in self.languages:
            self.langString += "1 as "+ language+", "
        self.langString =self.langString[0:len(self.langString)-2]
        self.postsFields = "id, AcceptedAnswerId, ParentId, CreationDate, Score, ViewCount, Body, OwnerUserId, OwnerDisplayName, LastEditorUserId, LastEditorDisplayName, LastEditDate, LastActivityDate, Title, Tags, AnswerCount, CommentCount, FavouriteCount, ClosedDate, CommunityOwnedDate"
        self.fields = "Tag, PostId, AcceptedAnswerId, ParentId, CreationDate, Score, ViewCount, Body, OwnerUserId, OwnerDisplayName, LastEditorUserId, LastEditorDisplayName, LastEditDate, LastActivityDate, Title, Tags, AnswerCount, CommentCount, FavouriteCount, ClosedDate, CommunityOwnedDate"
        self.valStr=""
        for field in self.fields.split(","):
            self.valStr += "'%s',"
        self.valStr = self.valStr[0:len(self.valStr)-2]
        self.dbConnect =DbConnect(self.dbConfig)
        Session, self.engine  = self.dbConnect.openConnection()
        self.session = Session()
        #Base.metadata.create_all(self.engine)

    def loadData(self, start=0, end=10338371):
        i=0;
        window = 1000
        j=i+window
        count = i
        keepLoading = True
        while keepLoading:
            keepLoading=False
#            
#            self.session.query(Questions).outerjoin(AcceptedAnswers).\
#...         filter(Questions.acceptedAnswerId==AcceptedAnswers.id).\
#...         all() 
            
            for row in self.session.query(Questions)[i:j]:
                keepLoading=True
                self.insertRow(row)
                count +=1
            i=j
            j=j+window
        print "done", count

    def insertRow(self, row):
        tags = self.processRow(row) # clean tags.
        lang = ''
        for tag in tags:
            if tag in self.languages:
                lang = tag
                if lang.lower()== 'c#':
                    lang = 'cSharp'
                elif lang.lower()=='c++':
                    lang = 'cPP'
                elif lang.lower() == 'ruby-on-rails':
                    lang = 'ruby_on_rails'
                elif lang.lower() == 'asp.net':
                    lang = 'asp_dot_net'
                elif lang.lower() == 'objective-c':
                    lang = 'objective_c'
                elif lang.lower() == 'node.js':
                    lang = 'node_dot_js'
                elif lang.lower() == 'visual-c++':
                    lang = 'visual_cPP'
                break;
        try:
            for tag in tags:
                self.addTagPost(row, lang=lang, tag=tag)
            self.session.commit()
        except Exception , e:
            print "ERROR: ", sys.exc_info()
            self.writeToFile(str(sys.exc_info()))
Ejemplo n.º 6
0
 def __init__(self):
     self.dbConnection = DbConnect()
Ejemplo n.º 7
0
from os import environ
from flask import Flask, jsonify
from BillAnalyser import BillAnalyser
from DbConnect import DbConnect
from flask import request
from flask_cors import CORS, cross_origin

app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
dbConnection = DbConnect()


@app.route('/api/bill', methods=['GET', 'POST'])
@cross_origin()
def get_bill():
    url = request.args.get('url')
    if dbConnection.is_bill_exist(url):
        billAnalyser = BillAnalyser(url)
        bill = billAnalyser.getBillSummary()
        dbConnection.add_bill(bill)
        return jsonify(dict(bill))
    return jsonify({})


@app.route('/')
def get_home():
    return "The server is up! :D"


# If Docker crashes try commenting/uncommenting the line below