示例#1
0
def main():
    """Shows basic usage of the Google Drive API.
    Creates a Google Drive API service object and outputs the names and IDs
    for up to 10 files.
    """
    credentials = get_credentials()

    credentials.authorize(httplib2.Http())
    token = str(credentials.access_token)

    if args.id:
        file = download__file_metadata(args.id, token, args.gid)
    else:
        i = 0
        service, files = getFiles(service)
        for item in files:
            print(str(item['title']) + " - " + str(item['id']))
            i += 1
        exit(1)

    content = file
    filename = "tmp" + '.csv'
    csvf = open(filename, 'w')
    csvf.write(content.decode("utf-8"))
    csvf.close()
    if args.platform == 'ios':
        translations.translate(filename, args.path)
    elif args.platform == 'android':
        translations.translate_android(filename, args.path)
    else:
        print("Invalid platform. type --help for help")
    if not args.keep_csv:
        os.remove(filename)
    print("Your files have been generated under '" + args.path + "'")
示例#2
0
    def manageSnippet(self, message: core.BotMessage) -> None:
        """Removes or adds a fact, topic, or quote

        Arguments:
            message {Message} -- the Message object that invoked the command
        """
        if message.room and len(message.arguments) > 1:
            room = message.room
            snippet = ",".join(message.arguments[1:]).strip()
        elif len(message.arguments) > 2:
            room = message.connection.getRoom(message.arguments[1])
            snippet = ",".join(message.arguments[2:]).strip()
        else:
            return message.respond(
                "You must specify a fact/topic/quote (and a room if used in PMs)."
            )

        if not message.sender.can("addfact", room):
            return message.respond("Permission denied.")
        if not re.match(r'[a-zA-Z0-9]', snippet): snippet = " " + snippet

        kind = 'Fact'
        snippetList = self.factList
        if "topic" in message.arguments[0]:
            kind = 'Topic'
            snippetList = self.topicList
        elif "quote" in message.arguments[0]:
            kind = 'Quote'
            snippetList = self.quoteList
        isAddition = "add" in message.arguments[0]

        if not snippetList: snippetList = {room.id: []}
        if room.id not in snippetList.keys():
            snippetList[room.id] = []

        if snippet not in snippetList[room.id] and isAddition:
            snippetList[room.id].append(snippet)
            message.respond(
                translations.translate(room,
                                       f"{kind} was successfully added!"))
        elif snippet in snippetList[room.id] and not isAddition:
            snippetList[room.id].remove(snippet)
            message.respond(
                translations.translate(room,
                                       f"{kind} was successfully removed!"))
        else:
            return message.respond(
                f"That {kind} is {'already' if isAddition else 'not'} in the room's list!"
            )

        if kind == 'Topic':
            self.topicList = snippetList
            return data.store("topicList", self.topicList)
        if kind == 'Quote':
            self.quoteList = snippetList
            return data.store("quoteList", self.quoteList)
        self.factList = snippetList
        return data.store("factList", self.factList)
示例#3
0
    def filterMessage(self, message: BotMessage) -> None:
        """Filters incoming messages and moderates on them if necessary

        Args:
            message (BotMessage): the message that is being filtered
        """
        if not message.sender or not message.room or not message.room.moderation:
            return
        if not self.points.get(message.room.id):
            self.points[message.room.id] = {}

        flooder = self.flooders.get(message.room.id)
        if flooder and len(flooder) >= 2 and message.sender.id == flooder[0]:
            self.flooders[message.room.id] = (message.sender.id,
                                              flooder[1] + 1)
        else:
            self.flooders[message.room.id] = (message.sender.id, 0)

        if message.sender.can('broadcast', message.room): return

        # Automatically moderate for bold
        if message.room.moderation.get('bold') and BOLD_REGEX.match(
                message.body):
            if not self.points[message.room.id].get(message.sender.id):
                self.points[message.room.id][message.sender.id] = 0
            self.points[message.room.id][message.sender.id] += 1
            return self.runPunish(
                message, translate(message.room,
                                   "do not abuse bold formatting"))

        # Automatically moderate for caps
        if message.room.moderation.get('caps') and CAPS_REGEX.match(
                message.body):
            if not self.points[message.room.id].get(message.sender.id):
                self.points[message.room.id][message.sender.id] = 0
            self.points[message.room.id][message.sender.id] += 1
            return self.runPunish(
                message, translate(message.room,
                                   "do not abuse capital letters"))

        # Automatically moderate for flooding
        if message.room.moderation.get(
                'flooding') and self.flooders[message.room.id][1] > 4:
            if not self.points[message.room.id].get(message.sender.id):
                self.points[message.room.id][message.sender.id] = 0
            self.points[message.room.id][message.sender.id] += 1
            return self.runPunish(
                message, translate(message.room, "do not flood the chat"))
示例#4
0
def main():
    """Shows basic usage of the Google Drive API.

    Creates a Google Drive API service object and outputs the names and IDs
    for up to 10 files.
    """
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('drive', 'v2', http=http)
    service, files = getFiles(service)

    i = 0

    if (args.id):
        for item in files:
            if item['id'] == args.id:
                file = item
    else:
        for item in files:
            print("[" + str(i) + "] " + str(item['title']) + " - " + str(item['id']))
            i += 1
        isDigit = False
        while not isDigit:
            _file = input("Select a file index: \n")
            isDigit = _file.isdigit()
            if int(_file) > len(files) or int(_file) < 0:
                print("Invalid index supplied. Try again")
                isDigit = False
        file = files[int(_file)]
    content = download_file(service, file)
    filename = file['id'] + '.csv'
    csvf = open(filename, 'w')
    csvf.write(content.decode("utf-8"))
    csvf.close()
    if args.platform == 'ios':
        translations.translate(filename, args.path)
    elif args.platform == 'android':
        translations.translate_android(filename, args.path)
    else:
        print("Invalid platform. type --help for help")
    if not args.keep_csv:
        os.remove(filename)
    print("Your files have been generated under '"+args.path+"'")
示例#5
0
def main():
    """Shows basic usage of the Google Drive API.
    Creates a Google Drive API service object and outputs the names and IDs
    for up to 10 files.
    """
    if not os.path.exists(CLIENT_SECRET_FILE):
        print('Enable the API and generate your ' + CLIENT_SECRET_FILE + ' and drag it in the same directory than this script '
                                                                         'https://console.developers.google.com/flows/enableapi?apiid=drive')

        exit(-1)
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('drive', 'v2', http=http)

    credentials.authorize(httplib2.Http())
    token = str(credentials.access_token)

    if args.id:
        file = download__file_metadata(args.id, token, args.gid)
    else:
        i = 0
        service, files = getFiles(service)
        for item in files:
            print(str(item['title']) + " - " + str(item['id']))
            i += 1
        exit(1)

    content = file
    filename = "tmp" + '.csv'
    csvf = open(filename, 'w')
    csvf.write(content.decode("utf-8"))
    csvf.close()
    if args.platform == 'ios':
        translations.translate(filename, args.path)
    elif args.platform == 'android':
        translations.translate_android(filename, args.path)
    else:
        print("Invalid platform. type --help for help")
    if not args.keep_csv:
        os.remove(filename)
    print("Your files have been generated under '"+args.path+"'")
示例#6
0
class Flashcard(BaseModel):
    front = CharField()
    back = CharField()
    times_correct = IntegerField()
    times_missed = IntegerField()


db.connect()

from translations import translate
import random

db.drop_tables([Flashcard])
db.create_tables([Flashcard])

translate()

print("\n BIENVENIDXS! What would you like to do?")


def train():

    action = input(
        "\n * 'create' to create a new card, \n * 'view' to view your deck of cards', \n * 'train' to review your cards. "
    )

    if action == "create" or action == "Create":
        new_card = input(
            "What Spanish word or phrase would you like to practice? Type in all lowercase. "
        )
        new_translation = input(