当前位置: 首页>>代码示例>>Python>>正文


Python MySQL.create_connection方法代码示例

本文整理汇总了Python中MySQL.MySQL.create_connection方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.create_connection方法的具体用法?Python MySQL.create_connection怎么用?Python MySQL.create_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySQL.MySQL的用法示例。


在下文中一共展示了MySQL.create_connection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_unprocessed_chromium_comments

# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import create_connection [as 别名]
    def download_unprocessed_chromium_comments(self,fptr, mysql_host, mysql_username, mysql_password, mysql_database, mysql_port):
       lines = fptr.readlines()
       filename = 'chromium_comments_unprocessed_' + str(int(time.time())) + '.txt'
       fopen = open(filename, 'a')
       chrome_sql_fopen = open('chromium_comments_sql_unprocessed_' + str(int(time.time())) + '.txt', 'a')

       for line in lines:
            issue_id = line.strip()
            time.sleep(2)

            try:
            
                num_comments = self.get_num_comments(issue_id)
                #print type(num_comments)
            
                if num_comments != 0 :
                    query = self.comment_feed_url % (issue_id, num_comments)
                    request = urllib2.Request(query)
                    response = urllib2.urlopen(request)
                    text = response.read()
                    comment_feed = json.loads(text)
                
                    #print num_comments
                    comment_entries = comment_feed['feed']['entry']
                    for comment_entry in comment_entries:
                    
                        try :                    
                            comment_id = comment_entry['id']['$t'].split('http://code.google.com/feeds/issues/p/chromium/issues/%s/comments/full/' % issue_id)[1]
                            #print issue_id, comment_id
                        except Exception, e:
                            print e

                    
                        try:
                            published = datetime.strptime(comment_entry['published']['$t'].split(".")[0], "%Y-%m-%dT%H:%M:%S")
                            #print published
                        except:
                            published = None
                            pass
                    
                        try:
                            updated = datetime.strptime(comment_entry['updated']['$t'].split(".")[0], "%Y-%m-%dT%H:%M:%S")
                            #print updated
                        except:
                            updated = None
                            pass
                    
                        try:
                            title = comment_entry['title']['$t']
                            #print title
                        except:
                            title = None
                        
                        
                        try:
                            content = unicodedata.normalize('NFKD', comment_entry['content']['$t']).encode('ascii', 'ignore')
                            #print content
                        except :
                            content = None
                    
                        try:
                            author = comment_entry['author'][0]['name']['$t']
                        except:
                            author = None
                        
                        
                        try :
                            issue_status = comment_entry['issues$updates']['issues$status']['$t']
                            #print issue_status
                        except :
                            issue_status = None
                            
                             try :
                            owner_update = comment_entry['issues$updates']['issues$ownerUpdate']['$t']
                            #print owner_update
                        except :
                            owner_update = None
                        
                    
                        try :

                            M = MySQL(mysql_host, mysql_username, mysql_password, mysql_database, mysql_port)
                            #print M.host, M.username, M.passwd, M.db, M.port
                            connection, cursor = M.create_connection() 
                            result = cursor.execute(self.insertCommentsQuery, (issue_id, comment_id, published, updated, title, content, author, issue_status, owner_update))
                            M.close_connection(cursor, connection)
                        
                        except Exception, e:
                            #print e
                            #print 'Unprocessed - ' +str(issue_id)                       
                            chrome_sql_fopen.write(str(issue_id) + '\n')
开发者ID:Mining-multiple-repos-data,项目名称:GoogleIssueTrackerDownload,代码行数:93,代码来源:ChromiumIssueTracker.py

示例2: download_android_comments

# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import create_connection [as 别名]
 def download_android_comments(self,start_issue_id, end_issue_id, mysql_host, mysql_username, mysql_password, mysql_database, mysql_port):
 
     for issue_id in range(start_issue_id, end_issue_id + 1):
         try:
             num_comments = self.get_num_comments(issue_id)
         
             query = self.comment_feed_url % (issue_id, num_comments)
             request = urllib2.Request(query)
             response = urllib2.urlopen(request)
             text = response.read()
             comment_feed = json.loads(text)
         
             #print num_comments
             comment_entries = comment_feed['feed']['entry']
             for comment_entry in comment_entries:
             
                 try :                    
                     comment_id = comment_entry['id']['$t'].split('http://code.google.com/feeds/issues/p/android/issues/%s/comments/full/' % issue_id)[1]
                     #print issue_id, comment_id
                 except Exception, e:
                     #print e
                     print
             
                 try:
                     published = datetime.strptime(comment_entry['published']['$t'].split(".")[0], "%Y-%m-%dT%H:%M:%S")
                     #print published
                 except:
                     published = None
                     pass
             
                 try:
                     updated = datetime.strptime(comment_entry['updated']['$t'].split(".")[0], "%Y-%m-%dT%H:%M:%S")
                     #print updated
                 except:
                     updated = None
                     pass
             
                 try:
                     title = comment_entry['title']['$t']
                     #print title
                 except:
                     title = None
                 
                 
                 try:
                     content = unicodedata.normalize('NFKD', comment_entry['content']['$t']).encode('ascii', 'ignore')
                     #print content
                 except :
                     content = None
             
                 try:
                     author = comment_entry['author'][0]['name']['$t']
                 except:
                     author = None
                 
                 
                 try :
                     issue_status = comment_entry['issues$updates']['issues$status']['$t']
                     #print issue_status
                 except :
                     issue_status = None
                 
             
                 try :
                     M = MySQL(mysql_host, mysql_username, mysql_password, mysql_database, mysql_port)
                     #print M.host, M.username, M.passwd, M.db, M.port
                     connection, cursor = M.create_connection() 
                     result = cursor.execute(self.insertCommentsQuery, (issue_id, comment_id, published, updated, title, content, author, issue_status))
                     M.close_connection(cursor, connection)
                 
                 except Exception, e:
                     #print e
                     #print 'Unprocessed - ' +str(issue_id)
                     filename = 'android_commentsql_unprocessed.txt'
                     fopen = open(filename, 'a')
                     fopen.write(str(issue_id) + '\n')
                     fopen.close()    
开发者ID:Mining-multiple-repos-data,项目名称:GoogleIssueTrackerDownload,代码行数:79,代码来源:AndroidIssueTracker.py

示例3: download_chromium_unprocessed_issue_reports

# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import create_connection [as 别名]

#.........这里部分代码省略.........
                        if value.lower() == 'os':
                            if os:
                                os = os + ',' + label['$t'].split('-')[1]
                            else:
                                os = label['$t'].split('-')[1]


                        if value.lower() == 'area':
                            area = label['$t'].split('-')[1]
                            #print area, type(area)   

                    
                        if value.lower() == 'feature':
                            if feature:
                                feature = feature + ',' + label['$t'].lower().split('feature-')[1]                                                    
                            else:
                                feature = label['$t'].lower().split('feature-')[1]
                                                

                        if value.lower() == 'mstone':
                            mstone = label['$t'].split('-')[1]
                            #print mstone, type(mstone)   
                        
                    
                        if value.lower() == 'releaseblock':
                            releaseBlock = label['$t'].split('-')[1]
                            #print releaseBlock

                        
                        
                        mod_label = unicodedata.normalize('NFKD', label['$t']).encode('ascii', 'ignore')
                    
                        if mod_label.lower()  == 'type-regression' or mod_label.lower() == "regression":
                            regression = True
                    
                        if mod_label.lower() == "performance" or mod_label.lower() == "type-performance" or mod_label.lower() == "stability-performance":
                            performance = True
                        
                        if mod_label.lower() == "cleanup" or mod_label.lower() == "type-cleanup":
                            cleanup = True
                        
                        if mod_label.lower() == "polish" or mod_label.lower() == "type-polish" or mod_label.lower() == "stability-polish":
                            polish = True
                    
                        if mod_label.lower() == "usability" or mod_label.lower() == "type-usability " or mod_label.lower() == "stability-usability":
                            usability =  True
                        
                        if mod_label.lower() == "crash" or mod_label.lower() == "type-crash" or mod_label.lower() == "stability-crash":
                            crash = True
                        
                        if mod_label.lower() == "security" or mod_label.lower() == "type-security":
                            security = True
            

                        if value.lower() == 'secseverity':
                            secSeverity = label['$t'].split('-')[1]
                            #print issue_id, secSeverity, type(secSeverity)   
                        
                                        
                        if value.lower() == 'webkit':                           
                            if webkit:   
                                webkit = webkit + ',' +  label['$t'].lower().split('webkit-')[1]
                            else:
                                webkit =  label['$t'].lower().split('webkit-')[1]
                    
                        if value.lower() == 'hotlist':
                            hotlist = label['$t'].lower().split('hotlist-')[1]
                    
                        if value.lower() == 'internals':
                            internals = label['$t'].split('Internals-')[1]                    
 
                        if value.lower() == 'sev':
                            sev = label['$t'].split('Sev-')[1]   

                        if value.lower() == 'secimpacts':
                            secImpacts = label['$t'].split('SecImpacts-')[1]   

                        if value.lower() == 'not':                           
                            if notLabel:   
                                notLabel = notLabel + ',' +  label['$t'].lower().split('not-')[1]
                            else:
                                notLabel =  label['$t'].lower().split('not-')[1]                    

                        if value.lower() == 'action':                           
                            if action:   
                                action = action + ',' +  label['$t'].lower().split('action-')[1]
                            else:
                                action =  label['$t'].lower().split('action-')[1] 

                except Exception, e:
                    print e
                    print 'No labels found ' + str(id)
                    pass
            
                print issue_id, action
    
                M = MySQL(mysql_host, mysql_username, mysql_password, mysql_database, mysql_port)
                connection, cursor = M.create_connection() 
                result = cursor.execute(self.insertIssueQuery,(issue_id, title, state, content, stars, owner, blocking, blockedOn, updated, status, closedDate, mergedInto, cc, author, published, bugtype, priority, pri, os, area, feature, mstone, releaseBlock, regression, performance, cleanup, polish, usability, crash, security, secSeverity, webkit, hotlist, internals, sev, secImpacts, notLabel, action, num_comments))
                M.close_connection(cursor, connection)
开发者ID:Mining-multiple-repos-data,项目名称:GoogleIssueTrackerDownload,代码行数:104,代码来源:ChromiumIssueTracker.py

示例4: download_android_issue_reports

# 需要导入模块: from MySQL import MySQL [as 别名]
# 或者: from MySQL.MySQL import create_connection [as 别名]

#.........这里部分代码省略.........
                try :
                    labels = issue_report['issues$label']
    #                print labels

                    restrict = None
                    target = None
                    bugtype = None
                    securityProblem = False
                    reportedBy = None
                    component = None
                    cat = None
                    priority = None
                    version = None
                    subcomponentopengl = None
                    subcomponent = None
                    regression = False
                
                
                    for label in labels:
                        value =  unicodedata.normalize('NFKD', label['$t'].split('-')[0]).encode('ascii', 'ignore')
                        #print value, type(value), value.lower() == 'type'
                    
                        if value.lower() == 'restrict':
                            restrict = label['$t'].split('-')[1]
    #                        print restrict

                    
                        if value.lower() == 'target':
                            target = label['$t'].split('-')[1]
                            #print target       

                        
                        if value.lower() == 'type':
                            bugtype = label['$t'].split('-')[1]
    #                        print type

                        
                        if value.lower() == 'securityproblem':
                            securityProblem  = True
    #                        print  securityProblem


                        if value.lower() == 'reportedby':
                            reportedBy = label['$t'].split('-')[1]
    #                        print reportedBy


                        if value.lower() == 'component':
                            component = label['$t'].split('-')[1]
    #                        print component
                        
                        
                        if value.lower() == 'cat':
                            cat = label['$t'].split('-')[1]
    #                        print cat        


                        if value.lower() == 'priority':
                            priority = label['$t'].split('-')[1]
    #                        print priority    

                        
                        if value.lower() == 'version':
                            version = label['$t'].split('-')[1]
    #                        print version                        


                        if value.lower() == 'subcomponentopengl':
                            subcomponentopengl = False
    #                        print subcomponentopengl
                        
                    
                        if value.lower() == 'subcomponent':
                            subcomponent = label['$t'].split('-')[1]
    #                        print subcomponent      
   

                        if value.lower() == 'regression':
                            regression = True
    #                        print regression'

                                      
                except:
                    #print 'No labels found ' + str(id)
                    pass            
               
        #        issue_query = insertQuery % (id, title, state, content, stars, owner, blocking, blockedOn, updated, status, closedDate, mergedInto, cc, author, published, restrict, target, securityProblem, reportedBy, component, cat, priority, version, subcomponentopengl, subcomponent, bugtype, regression)
                M = MySQL(mysql_host, mysql_username, mysql_password, mysql_database, mysql_port)
                #print M.host, M.username, M.passwd, M.db, M.port
                connection, cursor = M.create_connection() 
                result = cursor.execute(self.insertQuery, (issue_id, title, state, content, stars, owner, blocking, blockedOn, updated, status, closedDate, mergedInto, cc, author, published, restrict, target, securityProblem, reportedBy, component, cat, priority, version, subcomponentopengl, subcomponent, bugtype, regression, num_comments))
                M.close_connection(cursor, connection)
            
            except Exception, e:
                #print e
                #print 'Unprocessed - ' +str(issue_id)
                filename = 'android_issues_unprocessed.txt'
                fopen = open(filename, 'a')
                fopen.write(str(issue_id) + '\n')
                fopen.close()
开发者ID:Mining-multiple-repos-data,项目名称:GoogleIssueTrackerDownload,代码行数:104,代码来源:AndroidIssueTracker.py


注:本文中的MySQL.MySQL.create_connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。