Пример #1
0
 def GET(self):
     web.header('Access-Control-Allow-Origin', '*')
     web.header('Access-Control-Allow-Credentials', 'true')
     i = web.input(product=None)
     print "printing web.input: " + i.product
     db = DbConnection()
     result = db.select_one(i.product)
     return json.dumps(result)
Пример #2
0
def build_publisher_directory(startItemIndex, itemCount, addFolderToHierarchy):

    dbConnection = DbConnection.DbConnection()
    (publisherList,
     totalPubCount) = dbConnection.GetPublisherList(startItemIndex, itemCount)
    dbConnection.CloseDb()

    dir = XbmcDirectoryListing.XbmcDirectoryListing()
    dir.AddPreviousPageItem(startItemIndex, itemCount, {
        'mode': 'browse',
        'view': 'publisher'
    })

    for pub in publisherList:
        dir.AddItem(pub['name'], '',
                    Config.config.GetCompaniesImageCacheFile(pub['name']), {
                        'mode': 'romview_publisher',
                        'publisherid': pub['id']
                    }, True, True)

    dir.AddNextPageItem(startItemIndex, itemCount, totalPubCount, {
        'mode': 'browse',
        'view': 'publisher'
    })
    dir.Commit(addFolderToHierarchy)
Пример #3
0
def ScrapeRom( romId, romName, giantBombPlatformId, threadDbConnection ):

	dbConnection = threadDbConnection
	if dbConnection == None:
		dbConnection = DbConnection.DbConnection()

	romSearchResultsList = RomScraper.GetRomScraper().SearchForRomBlock( romName, giantBombPlatformId )
	if romSearchResultsList != None:
		searchResultCount = len( romSearchResultsList )
#						print "Search result count for rom '" + rowDict[ "name" ] + "' " + str( searchResultCount );
		if searchResultCount > 0:
			# todo: refine search results instead of just using first one
			romSearchResult = romSearchResultsList[0]
#							print rowDict[ "name" ] + " | " + romSearchResult[ 'giantBombApiDetailsUrl' ]
			romDetailsDict = RomScraper.GetRomScraper().GetRomDetailsBlock( romName, romSearchResult[ 'giantBombApiDetailsUrl' ] )
			if romDetailsDict != None:
				romDetailsDict[ 'name' ] = romName
				
				dbConnection.InsertRomScrapeRecords( romId, romDetailsDict )
				AddCompaniesToDb( dbConnection, romDetailsDict[ 'developers' ] )
				AddCompaniesToDb( dbConnection, romDetailsDict[ 'publishers' ] )
				AddGenresToDb( dbConnection, romDetailsDict[ 'genres' ] )
	
	if threadDbConnection == None:
		dbConnection.CloseDb()
Пример #4
0
    def onClick(self, controlID):

        if (controlID == CONTROL_BUTTON_PLAYGAME):
            xbmc.executebuiltin('XBMC.RunPlugin(' + sys.argv[0] +
                                '?mode=launch&romid=' + str(self.romId) + ' )')
            self.close()

        elif (controlID == CONTROL_WRAPLIST_SIMILARGAMES):
            # call PopulateFields with the new rom ID
            pos = self.getCurrentListPosition()
            if pos >= 0:
                selectedItem = self.getListItem(pos)
                if selectedItem != None:
                    romId = selectedItem.getProperty('romId')
                    if romId != None:
                        romIdInt = int(romId)
                        if romIdInt >= 0:
                            self.PopulateFields(romIdInt, True, True)

        elif (controlID == CONTROL_BUTTON_ADDFAVOURITE):
            addFavButton = self.getControlById(CONTROL_BUTTON_ADDFAVOURITE)
            if addFavButton != None:
                isSelected = addFavButton.isSelected()
                #			print "IS FAVOURITE: " + str( isSelected )
                dbConnection = DbConnection.DbConnection()
                dbConnection.SetRomFavourite(self.romId, isSelected)
                dbConnection.CloseDb()
Пример #5
0
def build_genre_directory(startItemIndex, itemCount, addFolderToHierarchy):

    dbConnection = DbConnection.DbConnection()
    (genreList,
     totalGenreCount) = dbConnection.GetGenreList(startItemIndex, itemCount)
    dbConnection.CloseDb()

    dir = XbmcDirectoryListing.XbmcDirectoryListing()
    dir.AddPreviousPageItem(startItemIndex, itemCount, {
        'mode': 'browse',
        'view': 'genre'
    })

    for genre in genreList:
        dir.AddItem(genre['name'], '',
                    Config.config.GetGenresImageCacheFile(genre['name']), {
                        'mode': 'romview_genre',
                        'genreid': genre['id']
                    }, True, True)

    dir.AddNextPageItem(startItemIndex, itemCount, totalGenreCount, {
        'mode': 'browse',
        'view': 'genre'
    })
    dir.Commit(addFolderToHierarchy)
Пример #6
0
def build_romview_directory(viewName, startItemIndex, itemCount,
                            addFolderToHierarchy):

    showFavourites = 0
    if viewName == 'favourites':
        showFavourites = 1

    dbConnection = DbConnection.DbConnection()
    isBestVersion = 1
    (romDataDictionaryList, totalRomCount) = dbConnection.SelectEmulatorRoms(
        '*', None, isBestVersion, showFavourites, 'name', 0, startItemIndex,
        itemCount)
    dbConnection.CloseDb()

    dir = XbmcDirectoryListing.XbmcDirectoryListing()
    dir.AddPreviousPageItem(startItemIndex, itemCount, {
        'mode': 'browse',
        'view': viewName
    })

    for rom in romDataDictionaryList:
        AddRomMenuItem(dir, rom)

    dir.AddNextPageItem(startItemIndex, itemCount, totalRomCount, {
        'mode': 'browse',
        'view': viewName
    })
    dir.Commit(addFolderToHierarchy)
Пример #7
0
def launch_rom(romId):

    dbConnection = DbConnection.DbConnection()
    romDataDictionary = dbConnection.GetRomById(romId)
    dbConnection.CloseDb()

    emuDict = Config.config.GetEmulatorByName(
        romDataDictionary['emulatorName'])

    print "Launching rom " + str(romId)
    Launcher.LaunchRom(emuDict, romDataDictionary)
Пример #8
0
def build_publisher_romview_directory(publisherId, startItemIndex, itemCount,
                                      addFolderToHierarchy):

    dbConnection = DbConnection.DbConnection()
    (romList, totalRomCount) = dbConnection.GetRomsByPublisherId(
        publisherId, startItemIndex, itemCount)
    dbConnection.CloseDb()

    dir = XbmcDirectoryListing.XbmcDirectoryListing()
    dir.AddPreviousPageItem(startItemIndex, itemCount, {
        'mode': 'romview_publisher',
        'publisherid': publisherId
    })

    for rom in romList:
        AddRomMenuItem(dir, rom)

    dir.AddNextPageItem(startItemIndex, itemCount, totalRomCount, {
        'mode': 'romview_publisher',
        'publisherid': publisherId
    })
    dir.Commit(addFolderToHierarchy)
Пример #9
0
def build_emulator_romview_directory(emulatorDictionary, startItemIndex,
                                     itemCount, addFolderToHierarchy):

    dbConnection = DbConnection.DbConnection()
    (romList, totalRomCount) = dbConnection.SelectEmulatorRoms(
        emulatorDictionary['name'], 0, 1, 0, 'name', 0, startItemIndex,
        itemCount)
    dbConnection.CloseDb()

    dir = XbmcDirectoryListing.XbmcDirectoryListing()
    dir.AddPreviousPageItem(startItemIndex, itemCount, {
        'mode': 'romview_emulator',
        'emulator': emulatorDictionary['name']
    })

    for rom in romList:
        AddRomMenuItem(dir, rom)

    dir.AddNextPageItem(startItemIndex, itemCount, totalRomCount, {
        'mode': 'romview_emulator',
        'emulator': emulatorDictionary['name']
    })
    dir.Commit(addFolderToHierarchy)
Пример #10
0
    def PopulateFields(self, romId, doClearList, doScrape):

        dbConnection = DbConnection.DbConnection()
        romDict = dbConnection.GetRomById(romId)

        # then add similar games as list items
        if doClearList == True:
            if self.getListSize() > 0:
                self.clearList()

        # remove item already in there if first used
        if self.getListSize() > 0:
            self.removeItem(0)

        self.SetProperty('label', romDict["name"])
        self.SetProperty('gameinfobig',
                         Config.config.GetRomsImageCacheFile(romDict["name"]))
        self.SetProperty('plot', romDict["description"])
        self.SetProperty(
            'releasedate',
            Config.config.FormatDateString(romDict["releaseDate"]))

        developerDictList = dbConnection.GetDevelopersByRomId(romId)
        self.SetProperty('developer',
                         self.MergeNamesAsString(developerDictList))

        publisherDictList = dbConnection.GetPublishersByRomId(romId)
        self.SetProperty('publisher',
                         self.MergeNamesAsString(publisherDictList))

        genreDictList = dbConnection.GetGenresByRomId(romId)
        self.SetProperty('genre', self.MergeNamesAsString(genreDictList))

        addFavButton = self.getControlById(CONTROL_BUTTON_ADDFAVOURITE)

        if romDict['isFavourite'] == 1:
            addFavButton.setSelected(True)
        else:
            addFavButton.setSelected(False)

        # set up similar games list
        similarGamesDict = dbConnection.GetRomSimilarGames(
            romId, Config.config.guiGameWindowSimilarGamesLimit)

        otherGamesList = []

        for sgDict in similarGamesDict:
            # for each similar game, see if it exists in the main db.
            otherRomDataDict = dbConnection.GetRomByGiantBombId(
                sgDict["otherRomGiantBombId"])

            if otherRomDataDict != None:  # this similar game exists in DB
                self.AddIfDoesNotExist(romId, otherGamesList, otherRomDataDict,
                                       ITEMTYPE_SIMILAR)

#		self.AddItem( -1, "", "", 0 )

# add roms from same developers to similar games list
        if developerDictList != None:
            for dataDict in developerDictList:
                (otherRomDataDictList,
                 developerCount) = dbConnection.GetRomsByDeveloperId(
                     dataDict['id'], 0,
                     Config.config.guiGameWindowDeveloperGamesLimit)
                if otherRomDataDictList != None:
                    for otherRomDataDict in otherRomDataDictList:
                        self.AddIfDoesNotExist(romId, otherGamesList,
                                               otherRomDataDict,
                                               ITEMTYPE_DEVELOPER)

#		self.AddItem( -1, "", "", 0 )

# same for publisher
        if publisherDictList != None:
            for dataDict in publisherDictList:
                (otherRomDataDictList,
                 publisherCount) = dbConnection.GetRomsByPublisherId(
                     dataDict['id'], 0,
                     Config.config.guiGameWindowPublisherGamesLimit)
                if otherRomDataDictList != None:
                    for otherRomDataDict in otherRomDataDictList:
                        self.AddIfDoesNotExist(romId, otherGamesList,
                                               otherRomDataDict,
                                               ITEMTYPE_PUBLISHER)

        for game in otherGamesList:
            (otherRomDataDict, itemType) = game
            self.AddItem(
                otherRomDataDict["id"], otherRomDataDict["name"],
                Config.config.GetRomsImageCacheFile(otherRomDataDict["name"]),
                itemType)

        dbConnection.CloseDb()

        self.UpdateSimilarGamesText()

        if doScrape == True:
            if romDict['isScraped'] != 1:
                self.doClearList = doClearList
                self.DoScrape(romId, romDict)
Пример #11
0
import json
from sys import argv
import simplejson as json
import DbConnection

tweets_filename = 't2.txt'
tweets_file = open(tweets_filename, "r")
con = DbConnection.dbConnection()

with con:
	cur = con.cursor()
	cur.execute("delete from global_tweets")
	cur.execute("delete from current_global_tweets")
	cur.execute("delete from filter_global_tweets")
	cur.execute("delete from filter_local_tweets")

for line in tweets_file:
    try:
        
        tweet = json.loads(line.strip())
        if 'text' in tweet: 
           
	    with con:
		cur = con.cursor()
		cur.execute("INSERT INTO global_tweets(id,created_at,tweets) VALUES(%s,%s,%s)",(tweet['user']['screen_name'],tweet['created_at'],tweet['text'].encode("ascii", "ignore")))
                cur.execute("INSERT INTO current_global_tweets(id,created_at,tweets) VALUES(%s,%s,%s)",(tweet['user']['screen_name'],tweet['created_at'],tweet['text'].encode("ascii", "ignore")))

	    hashtags = []
            for hashtag in tweet['entities']['hashtags']:
            	hashtags.append(hashtag['text'])
           
Пример #12
0

# In[ ]:


dbcon.create_table(table_name,column_name,dbcon.
                   get_dbCon())


# ## Insert data from data_xml_3 dataframe to covid19_xml_tbl

# In[ ]:


db_column=['countriesandterritories','cases','deaths']
dbcon.insert_csv_table(data_xml_3,table_name,db_column)


# In[20]:


## CHECK the insetion part
dbcon.select_count(table_name,dbcon.get_dbCon())


# ## Pre-Process the web scrapping and store into postgre

# In[21]:


data_web=pd.read_csv('data/web_data_covid19.csv')
Пример #13
0
def init_db():
    dbConnection = DbConnection.DbConnection()
    dbConnection.CreateTables()
    dbConnection.CloseDb()
Пример #14
0
 *                                                                         *
 ***************************************************************************/
"""
# Import the PyQt and QGIS libraries
from PyQt4 import uic
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
import DbConnection
import highlighter as hl
import os
import resources

# Initialize Qt resources from file resources.py

conn = DbConnection.ConnectionManager()


class PostgisLayer:
    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface

    def initGui(self):
        # Create action that will start plugin configuration
        self.action = QAction(QIcon(":/plugins/postgislayer/icon.png"),
                              "Fast SQL Layer", self.iface.mainWindow())
        #Add toolbar button and menu item
        self.iface.addPluginToDatabaseMenu("&Fast SQL Layer", self.action)
        #self.iface.addToolBarIcon(self.action)
Пример #15
0
def RefreshRomsBackgroundThread( emulatorName, giantBombPlatformId, romsPath, romsFilter, progressCallback, progressData, finishedCallback, finishedData ):

	threadDbConnection = None
	totalRomsProcessed = 0
	
	try:
		threadDbConnection = DbConnection.DbConnection()	
		threadDbConnection.ClearRoms( emulatorName )
		
		allFiles = GetAllFilesInDirectory( romsPath, romsFilter )
		
		fileCount = len( allFiles )
		print ( 'Discovered ' + str( fileCount ) + ' rom files' )
		
		if ( fileCount > 0 ):
			dbRows = []

			# build original array
			fileIndex = 0
			for file in allFiles:
				if progressCallback( progressData, fileIndex, fileCount, emulatorName, "Discovering", file ) == False:
					return

				fullPath = os.path.join( romsPath, file )
				( romName, romState, territory ) = DetermineRomNameAndState( fullPath )
				rowDict = { "fullPath": fullPath, "emulatorName": emulatorName, "romName": romName, "romState": romState, "territory": territory, "isBestVersion": 0 }
				dbRows.append( rowDict )

				fileIndex = fileIndex + 1
			
			# check for duplicates, find best version of each rom
			CheckForDuplicates( dbRows )
			
			threadDbConnection.InsertRomRecords( emulatorName, dbRows )
			
			# TODO: put in option to do scrape during refresh
			isScraping = 1
			
			# if we are scraping, read the roms back out the db and scrape each one
			if isScraping > 0:
				# for now, only scrape 'best version' roms
				( romDataDictionaryList, totalRomCount ) = threadDbConnection.SelectEmulatorRoms( emulatorName, 0, 1, 0, 'name', 0, 0, 0 )
			
				romIndex = 0
				for rowDict in romDataDictionaryList:
					if progressCallback( progressData, romIndex, totalRomCount, emulatorName, "Scraping", rowDict[ "name" ] ) == False:
						return
					ScrapeRom( rowDict[ "id" ], rowDict[ "name" ], giantBombPlatformId, threadDbConnection )
					
					romIndex += 1
					totalRomsProcessed += 1


	except Exception as e:
		logging.exception(e)

	finally:
		if threadDbConnection != None:
			threadDbConnection.CloseDb()
			del threadDbConnection
		if progressCallback != None:
			del progressCallback
		if finishedCallback != None:
			print "Calling finishedCallback"
			finishedCallback( finishedData )
			del finishedCallback
	
	return totalRomsProcessed
Пример #16
0
    print "---------------"

    return True


def OnExit():
    g_exitted = True
    return False


if sys.version_info.major != 2 and sys.version_info.minor != 7:
    print(
        "Cannot run script: You must use python 2.7 (You are trying to use " +
        str(sys.version_info.major) + "." + str(sys.version_info.minor) + ")")
else:
    import Config, DbConnection, RomScraper

    resourcesPath = 'resources'
    Config.config.Init(resourcesPath)

    dbConnection = DbConnection.DbConnection()
    dbConnection.CreateTables()
    dbConnection.CloseDb()

    DisplayMenuOptions('Please select an option',
                       [('Add emulator', OnAddEmulator),
                        ('Remove emulator', OnRemoveEmulator),
                        ('List emulators', OnListEmulators), ('Exit', OnExit)])

    print "--------------------------------------------"
Пример #17
0
import json
from sys import argv
import simplejson as json
import DbConnection

tweets_filename = 't2.txt'
tweets_file = open(tweets_filename, "r")
con = DbConnection.dbConnection()

with con:
    cur = con.cursor()
    cur.execute("delete from global_tweets")
    cur.execute("delete from current_global_tweets")
    cur.execute("delete from filter_global_tweets")
    cur.execute("delete from filter_local_tweets")

for line in tweets_file:
    try:

        tweet = json.loads(line.strip())
        if 'text' in tweet:

            with con:
                cur = con.cursor()
                cur.execute(
                    "INSERT INTO global_tweets(id,created_at,tweets) VALUES(%s,%s,%s)",
                    (tweet['user']['screen_name'], tweet['created_at'],
                     tweet['text'].encode("ascii", "ignore")))
                cur.execute(
                    "INSERT INTO current_global_tweets(id,created_at,tweets) VALUES(%s,%s,%s)",
                    (tweet['user']['screen_name'], tweet['created_at'],
Пример #18
0
    def __init__(self):
        # base constructor
        super(Application, self).__init__(sys.argv)

        # make settings object, read existing settings
        # FIXME only tested on Linux
        self.settings = QtCore.QSettings(
            os.getenv('HOME') + '/.sacredbrowserrc',
            QtCore.QSettings.IniFormat)

        # prepare database access (does not do anything)
        self.connection = DbConnection.DbConnection(self)
        self.dbModel = DbModel.DbModel(self)
        self.collectionModel = CollectionModel.CollectionModel(self)

        # current database and collection (as pymongo objects)
        self.currentDatabase = None
        self.currentRunCollection = None

        # create main window
        self.mainWin = MainWin.MainWin(self)
        self.mainWin.show()

        # create non-modal sort dialog
        self.sortDialog = SortDialog.SortDialog()
        self.sortDialog.closeCalled.connect(self.slotSortDialogClosed)

        # connect signals/slots from main window
        self.mainWin.dbTree.activated.connect(self.slotChooseCollection)
        self.mainWin.connectToDb.clicked.connect(
            self.slotConnectToMongoDbInstance)

        # subwidgets in the main window
        self.mainWin.fieldChoice.fieldChoiceChanged.connect(
            self.collectionModel.slotFieldSelectionChanged)
        self.mainWin.quickDelete.stateChanged.connect(
            self.collectionModel.slotAllowQuickDeleteToggled)
        self.sortDialog.sortOrderChanged.connect(
            self.collectionModel.slotSortOrderChanged)
        self.mainWin.filterChoice.doNewSearch.connect(
            self.collectionModel.slotDoNewSearch)

        # display settings and controls
        self.mainWin.resultViewGroup.buttonClicked[int].connect(
            self.collectionModel.slotResultViewChanged)
        self.mainWin.sortButton.toggled.connect(self.slotSortDialogToggled)
        self.mainWin.deleteButton.clicked.connect(
            self.collectionModel.slotDeleteSelection)
        self.mainWin.copyButton.clicked.connect(
            self.collectionModel.slotCopyToClipboard)
        self.mainWin.fullEntryButton.clicked.connect(
            self.collectionModel.slotFullEntry)
        self.mainWin.collectionView.horizontalHeader().sectionResized.connect(
            self.collectionModel.slotSectionResized)
        self.mainWin.resetColWidthButton.clicked.connect(
            self.collectionModel.slotResetColWidth)

        self.aboutToQuit.connect(self.finalCleanup)

        # set initial values for check boxes
        quickDeleteChecked = self.settings.value('Global/quickDeleteChecked')
        if quickDeleteChecked.isValid():
            self.mainWin.quickDelete.setChecked(quickDeleteChecked.toBool())

        self.mainWin.resultViewRaw.setChecked(True)
        self.mainWin.resultViewRounded.setChecked(False)
        self.mainWin.resultViewPercent.setChecked(False)

        self.showStatusMessage('Welcome to SacredAdmin!')
Пример #19
0
 def __init__(self):
     dc = DbConnection()
     self.conn = dc.getConnection()
Пример #20
0
 def __init__(self):
     dc = DbConnection.DbConnection()
     self.dc = dc
     self.conn = dc.getConnection()
     self.cursor = self.conn.cursor()
     self.el = ErrorLog.ErrorLog()
Пример #21
0
 def GET(self):
     web.header('Access-Control-Allow-Origin', '*')
     web.header('Access-Control-Allow-Credentials', 'true')
     db = DbConnection()
     result = db.select_all()
     return json.dumps(result)