예제 #1
0
 def add_blacklist(self, tolist):
     myhelper = DatabaseHelper()
     valid = myhelper.add_blacklist(self, tolist)
     if valid:
         self.blacklist.append(tolist)
         return True
     else:
         return False
예제 #2
0
 def add_whitelist(self, tolist):
     myhelper = DatabaseHelper()
     valid = myhelper.add_whitelist(self, tolist)
     if valid:
         self.whitelist.append(tolist)
         return True
     else:
         print("nope")
         return False
예제 #3
0
def main(termsList, xliffFile):

    # Loads terms List into Term Loader
    termLoader = PhraseLoader.TermLoader(termsList)
    termLoader.loadTerms()

    # Grabs Terms to be saved and terms not being saved in database
    specTermDictForDatabase, specTermDictNoSave = termLoader.getTermDicts()
    database = db.DatabaseHelper()

    # Parses xliff file into a list of trees
    parser = XLIFFParser2.XMLParser(xliffFile)
    parsedTree = parser.run()

    # Grabs content pairs
    extractor = ExtractContent.TagBinder(parsedTree)
    IPCCODEGENERIC, IPCODESPECIFIC = extractor.findIPCCode()

    # Fetches relevant IPC Code terms from database
    genTermDict = database.getTerms(IPCCODEGENERIC)

    # creates output file in same directory as the xliff file
    output = open(getFileDir(xliffFile) + "output_check.txt", "w+")

    # For SDLXLIFF Files
    matchList = extractor.findSourceTargetMatch("seg-source", "target")

    # For XLIFF Files
    # TODO: add XLIFF functionality
    # matchList += extractor.findSourceTargetMatch("source", "target")

    # Runs check
    k = Validator(
        {**genTermDict, **specTermDictForDatabase, **specTermDictNoSave},
        output,
        matchList,
    )
    phraseResults = k.run()

    # Runs reference tag check
    refChecker = ReferenceNumberCounter.CompareReferenceElements(matchList, output)
    refResults, numResults = refChecker.compareTexts()

    # Write output file
    k.writeResults(phraseResults, refResults, numResults)

    # add relevant terms to dictionary and rewrite to database
    database.setTerms(specTermDictForDatabase, IPCCODEGENERIC)
    database.updateDatabase()

    output.close()
예제 #4
0
 def load_info(self):
     myhelper = DatabaseHelper()
     wl = myhelper.get_whitelist(self)
     for tup in wl:
         for ip in tup:
             self.whitelist.append(ip)
     bl = myhelper.get_blacklist(self)
     for tup in bl:
         for ip in tup:
             self.blacklist.append(ip)
     fw = myhelper.get_firewall(self)
     for tup in fw:
         try:
             self.firewall = Firewall(tup[0], tup[1])
         except:
             print("default firewall")
예제 #5
0
def send_nearest_atm(message):
    print(message)
    bot.send_chat_action(message.chat.id, "typing").wait()
    db = DatabaseHelper.DatabaseHelper(settings.DATABASE_NAME, settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_HOST, settings.DATABASE_PORT)
    result = db.select_atms(message.location.longitude, message.location.latitude)
    if len(result) == 0:
        result = db.select_atms(message.location.longitude, message.location.latitude, 6000)
    db.close()
     
    if len(result) == 0:
        bot.send_message(message.chat.id, "К сожалению, поблизости нет банкоматов.").wait()
    else:
        bot.send_location(message.chat.id, result[0][3], result[0][2]).wait()
        descr_text = '''Ближайший банкомат :
Адрес:{}
{}
Расстояние: {} м.'''.format(result[0][0], result[0][1], result[0][4])
        bot.send_message(message.chat.id, descr_text).wait()
예제 #6
0
파일: Admin.py 프로젝트: nBoyd-98/IP-Banner
 def remove_server(self, toremove):
     myhelper = DatabaseHelper()
     myhelper.remove_server(toremove)
     del self.serverdict[toremove.alias]
     self.servercount -= 1
예제 #7
0
파일: Admin.py 프로젝트: nBoyd-98/IP-Banner
 def add_server(self, new_server):
     myhelper = DatabaseHelper()
     myhelper.add_server(self.username, new_server)
     self.serverdict[new_server.alias] = new_server
     self.serverlist.append(new_server)
     self.servercount += 1
예제 #8
0
 def __init__(self):
     self.db = helper.DatabaseHelper()
     pass
예제 #9
0
from DatabaseHelper import *

SAVELOCATION = os.getcwd() + "\\webcomics\\"

# Load each web series from the json into a list of webcomic objects
webseries = []
openJson = open('webcomiclist.json')
data = json.load(openJson)
for webcomic in data["webcomics"]:
    webseries.append(
        Webcomic(webcomic["name"], webcomic["baseURL"], webcomic["startURL"],
                 webcomic["nextURLXPath"], webcomic["comicXPath"],
                 webcomic["genres"]))

# Connect to the database. If the database does not exist it will be created.
databaseHelper = DatabaseHelper("WebcomicDatabase.db")

# Iterate through every webseries
for comic in webseries:
    # Is this the first comic to be downloaded (false), or are we picking up where we left off (true)
    print(comic.name)
    comicsToDownload = True
    saveTo = SAVELOCATION + comic.name + "\\"

    # If the directory for this webseries does not exist, create it
    if not os.path.exists(saveTo):
        os.makedirs(saveTo)

    # Get the webseries data from the database. If it does not exist in the database this will return None.
    webseriesData = databaseHelper.getWebseriesData(comic.name)
예제 #10
0
 def remove_blacklist(self, toremove):
     self.blacklist.remove(toremove)
     myhelper = DatabaseHelper()
     myhelper.remove_blacklist(self, toremove)
예제 #11
0
 def remove_whitelist(self, toremove):
     self.whitelist.remove(toremove)
     myhelper = DatabaseHelper()
     myhelper.remove_whitelist(self, toremove)
예제 #12
0
def main():
    db = DatabaseHelper()
    server = Server("test", "test", "test", "test")
    blacklist = db.add_blacklist(server, "1.1.1.1")
class GPSGUI(object):
    db = DatabaseHelper("SpeedLimits.db")

    def __init__(self, view, guiType):
        self.view = view
        if guiType == 0:

            lat_text = StringVar()
            self.lat_entry = Entry(self.view, textvariable=lat_text)

            lon_text = StringVar()
            self.lon_entry = Entry(self.view, textvariable=lon_text)

            self.street_label = Label(self.view, text="--", width=25)
            self.speed_limit_label = Label(self.view, text="-- mph")
            self.search_time = Label(self.view, text="Search Time:")
            self.search_time_label = Label(self.view, text="-- seconds")

            self.manualGUI(self.view)

        elif guiType == 1:
            self.lat_label = Label(self.view, text="Latitude: --")
            self.lon_label = Label(self.view, text="Longitude: --")
            self.speed_label_num = Label(self.view, text="80")
            self.speed_label_unit = Label(self.view, text="mph")
            self.speed_limit_label = Label(self.view, text="Speed Limit: --")
            self.autoGUI(view)
        else:
            print("invalid GUI specification")
            return

    def manualGUI(self, view):

        lat_label = Label(view, text="Lat: ")
        lat_label.grid(row=0, column=0)

        lat_text = StringVar()
        self.lat_entry = Entry(view, textvariable=lat_text)
        self.lat_entry.grid(row=0, column=1, columnspan=2)

        lon_label = Label(view, text="Lon: ")
        lon_label.grid(row=0, column=3)

        self.lon_entry.grid(row=0, column=4, columnspan=2)

        enter_button = Button(view, text="Query", command=self.get_limit)
        enter_button.grid(row=0, column=6)

        road_label = Label(view, text="Road: ")
        road_label.grid(row=1, column=0, columnspan=2)
        road_label.config(font=("Times New Roman", 40))

        self.street_label.grid(row=1, column=2, columnspan=5)
        self.street_label.config(font=("Times New Roman", 40))

        self.speed_limit_label.grid(row=2, column=2, rowspan=2, columnspan=4)
        self.speed_limit_label.config(font=("Times New Roman", 80))

        self.search_time.grid(row=4, column=4)
        self.search_time_label.grid(row=4, column=5)

    def autoGUI(self, view):
        self.lat_label.grid(row=0, column=0, columnspan=2)
        self.lon_label.grid(row=0, column=2, columnspan=2)

        self.speed_label_num.grid(row=1, column=0, columnspan=3)
        self.speed_label_num.config(font=("Times New Roman", 80))

        self.speed_label_unit.grid(row=1, column=3, columnspan=1)
        self.speed_label_unit.config(font=("Times New Roman", 20))

        self.speed_limit_label.grid(row=2, column=0, columnspan=4)
        self.speed_limit_label.config(font=("Times New Roman", 40))
        print("AutoGUI")

    def get_limit(self):
        start = time.clock()
        vals = self.db.get_speed_limit(float(self.lat_entry.get()),
                                       float(self.lon_entry.get()))
        end = time.clock()
        self.search_time_label.config(text='{0:.5f} seconds'.format(end -
                                                                    start))

        if type(vals) != str:
            print('{0}, {1}'.format(vals[0], vals[1]))
            self.street_label.config(text='{0}'.format(vals[0]))
            self.speed_limit_label.config(text='{0} mph'.format(vals[1]))
            self.set_speed(vals[1])
        else:
            self.street_label.config(text='{0}'.format(vals))
            self.speed_limit_label.config(text='-- mph')
            print(vals)
        print("ManualGUI")

    @staticmethod
    def set_speed(speed):
        new_line = 'Max Speed:{0}'.format(speed) + '\n'
        config_temp = 'Para.cfg'
        with open(config_temp, 'r+') as f:
            content = f.readlines()
            f.seek(0)
            for line in content:
                if 'Max Speed' in line:
                    line = line.replace(line, new_line)
                f.write(line)
            f.truncate()