Example #1
0
 def parse(cls, buf):
     buf = str(buf)
     buf = buf.replace("'", '"') 
     
     data  = json.loads(buf)   
     srcDevUUID  = data['srcDevUUID']
     deltaUpdate = data['deltaUpdate']
     
     contentListJSON = data['contentList']
     contentList = []
     for c in contentListJSON:
        
         contentId   = c['contentId']
         size        = c['size']
 
         tagListJSON = c['tagList']
         tagList = []
         for t in tagListJSON:
             newTag = Tag(t['name'], t['quality']) 
             tagList.append(newTag)
                 
         newContent = Content(contentId, size)
         newContent.tagList = tagList
         contentList.append(newContent)
         
     return cls(srcDevUUID, deltaUpdate, contentList)
 def _leftClickTreeRelease(self, event):
     if self.dragstate != DragState.NONE:
         if self.dragstate == DragState.SUCCESS:
             newparent = Content.data.findGroup(
                 self._getItemPathByTreeId(self.tree.selection()))
             newparent.modified = True
             movetype = self.treeselection[4]
             if movetype == 'group':
                 moveitem = Content.data.findGroup(self.treeselection[0])
                 moveitem.parent.children.remove(moveitem)
                 moveitem.parent.modified = True
                 moveitem.parent = newparent
                 newparent.children.append(moveitem)
                 newparent.sortGroups()
             elif movetype == 'entry':
                 moveitem = Content.data.findEntry(self.treeselection[0])
                 moveitem.parent.entries.remove(moveitem)
                 moveitem.parent.modified = True
                 moveitem.parent = newparent
                 newparent.entries.append(moveitem)
                 newparent.sortEntries()
             Content.markRestorePoint()
             Content.contentMutated()
             self.tree.item(self._findTreeIndexByPath(newparent.getPath()),
                            open=YES)
             self.tree.selection_set(
                 self._findTreeIndexByPath(moveitem.getPath()))
         else:
             # If we didn't succeed, reset the selection back to the start
             self.tree.selection_set(
                 self._findTreeIndexByPath(self.treeselection[0]))
         self.dragstate = DragState.NONE
Example #3
0
 def _pageModified(self, event):
     pane = self.pageEditPane.get('1.0', END).rstrip()
     self.page.content = pane
     self.page.parent.parent.modified = True
     # Content.markRestorePoint() # TODO this was too slow
     Content.contentMutated()
     self._updateDetails()
Example #4
0
 def AnaLex(self):
     res = []
     index = 0
     for i in self.__contentOfFile:
         ContentAux = Content()
         aux = i.content.split()
         for j in aux:
             if (j in self.__keywords):
                 ContentAux.line = i.line
                 ContentAux.content = self.__keywords[j]
                 ContentAux.att = j
                 self.__Tokens.append(ContentAux)
                 self.__contentOfFile[index].content = self.__contentOfFile[
                     index].content.replace(j, '')
         index += 1
     self.evaluateTokensNoAtt()
     for i in self.__contentOfFile:
         splitted = i.content.split()
         for j in splitted:
             ContentAux = Content()
             if (j != ''):
                 atribute = self.regularexpressions(j)
                 ContentAux.line = i.line
                 ContentAux.att = atribute
                 ContentAux.content = j
                 self.__Tokens.append(ContentAux)
     return self.__Tokens
Example #5
0
 def post(self):
     from user_sn import confirm
     u = confirm(self)
     from Content import Content, TYPE_BOOK, set_file_id
     c = Content(SharedBy = u, Name = self.request.get("title"),Type=TYPE_BOOK,Link=self.request.get("amzn"))
     set_file_id(c)
     c.put()
     self.response.out.write("/share/upload?key=%s" % c.file_id)
Example #6
0
 def parse(self, site, url):
     """Get text from url"""
     bs = self.getPage(url)
     if bs is not None:
         title = self.safeGet(bs, site.titleTag)
         if title != '':
             content = Content(url, title)
             content.print()
Example #7
0
 def _colorChanged(self, *args):
     if self.colorvar.get() == ' ':
         return
     newtype = EntryColors[self.colorvar.get()]
     if self.lastentry.entrycolor != newtype:
         self.lastentry.entrycolor = newtype
         self.lastentry.modified = True
         Content.markRestorePoint()
         Content.contentMutated()
Example #8
0
 def _typeChanged(self, *args):
     if self.typevar.get() == ' ':
         return
     newtype = EntryType[self.typevar.get()]
     if self.lastentry.entrytype != newtype:
         self.lastentry.entrytype = newtype
         self.lastentry.modified = True
         Content.markRestorePoint()
         Content.contentMutated()
 def _doubleClickTree(self, event):
     iid = self.tree.identify_row(event.y)
     if iid:
         # We really only respond to double clicking on entries
         val = self._getItemValuesByTreeId(iid)
         if val[4] != 'entry':
             return
         Content.editEntry = Content.data.findEntry(val[0])
         Content.contentMutated()
Example #10
0
 def __init__(self, path):
     super(TableFactory, self).__init__()
     self.path = path
     self.image = cv2.imread(self.path)
     self.image_display = self.image.copy()
     self.gray = self.__prepare_image_gray()
     self.gray_display = self.gray.copy()
     self.content_extractor = Content()
     self.tree_of_content = self.content_extractor.paris_dichotomie(self.image, self.gray)
Example #11
0
 def __init__(self):
     super(ImageFactory, self).__init__()
     self.path = None
     self.image = None
     self.gray = None
     self.feature_extractor = Projection()
     self.content_extractor = Content()
     self.content_list = None
     self.feature_list = np.array([])
     self.class_list = np.array([])
     # for display purpose
     self.display = None
Example #12
0
 def deleteRegion(self):
     if len(Content.allregions) < 2:
         messagebox.showwarning(title='Delete Region',
                                message='Can\'t delete the last region.')
         return
     if messagebox.askyesno(
             'Delete Region?',
             'Are you sure you want to delete the region named \'' +
             Content.region + '\'?',
             default=messagebox.NO):
         Content.deleteRegion(Content.region)
         self.refreshViews()
Example #13
0
 def replaceEntry(self, entry, preFlag = None):
     nEntry = entry.clone()
     if preFlag is not None:
         nPreContent = nEntry.getPreContent()
         if nPreContent is None:
             nPreContent = Content(preFlag)
             nEntry.setPreContent(nPreContent)
         else:
             nPreContent.append(preFlag)
     
     result = self.mParser.replaceEntry(nEntry)
     self.mModifed = True
     return result
Example #14
0
    def do_GET(self):
        # Send response status code
        self.send_response(200)

        # Send headers
        self.send_header('Content-type', 'text/html')
        self.end_headers()

        # Send message back to client
        content = Content()
        message = content.getHtmlContentByRequest('simpleTemplate')
        # Write content as utf-8 data
        self.wfile.write(bytes(message, "utf8"))
        return
    def extract_direct_mislinked(self):
        """
        All direct links to imgur.com must start with 'https://i.imgur.  Sometimes links get mis labeled somehow when
        they are posted.  This method is to add the correct address beginning to mislinked imgur urls and get a proper
        extraction
        """
        for ext in ['.jpg', '.jpeg', '.png', '.gif', '.gifv', '.mp4', '.webm']:
            if ext in self.url:
                index = self.url.find(ext)
                url = '%s%s' % (self.url[:index], ext)

        domain, id_with_ext = url.rsplit('/', 1)
        domain = 'https://i.imgur.com/'
        url = '%s%s' % (domain, id_with_ext)
        image_id, extension = id_with_ext.rsplit('.', 1)
        file_name = self.post_title if self.name_downloads_by == 'Post Title' else image_id
        if url.endswith('gifv') or url.endswith('gif'):
            picture = self.client.get_image(image_id)
            if picture.type == 'image/gif' and picture.animated:
                url = picture.mp4
                extension = 'mp4'
        x = Content(url, self.user, self.post_title, self.subreddit, file_name,
                    "", '.' + extension, self.save_path,
                    self.subreddit_save_method)
        self.extracted_content.append(x)
 def _actionDuplicate(self):
     duplicatetype = self.treeselection[4]
     if duplicatetype == 'group':
         group = Content.data.findGroup(self.treeselection[0])
         self.verifygroup = group.parent
         group.parent.addGroup(
             self._incrementName(group.id, self._validateGroup))
         group.parent.modified = True
     elif duplicatetype == 'entry':
         entry = Content.data.findEntry(self.treeselection[0])
         self.verifygroup = entry.parent
         entry.parent.addEntry(
             self._incrementName(entry.id, self._validateEntry))
         entry.parent.modified = True
     Content.markRestorePoint()
     Content.contentMutated()
Example #17
0
def getShootContent(player):
    strike = EnergyStrike(pygame, gameDisplay, gameParams)
    shootContent = Content(
        strike,
        firstStage.getShootConduct((player.get_x() + 20, player.get_y() - 5)),
        1)
    return [shootContent]
 def create_content_from_extract(self, url, url_id, number):
     address, extension = url.rsplit('.', 1)
     file_name = self.post_title if self.name_downloads_by == 'Post Title' else url_id
     x = Content(url, self.user, self.post_title, self.subreddit, file_name,
                 number, '.' + extension, self.save_path,
                 self.subreddit_save_method)
     self.extracted_content.append(x)
 def _actionNewGroup(self):
     self.verifygroup = Content.data.findGroup(self.treeselection[0])
     popup = PopupDialog(self.master,
                         "New Group",
                         validate=self._validateGroup)
     if popup.result:
         result = self.verifygroup.addGroup(popup.result)
         self.verifygroup.modified = True
         Content.markRestorePoint()
         Content.contentMutated()
         iid = self._findTreeIndexByPath(result.parent.getPath())
         if iid:
             self.tree.item(iid, open=YES)
             iid = self._findTreeIndexByPath(result.getPath())
             if iid:
                 self.tree.selection_set(iid)
 def extract_direct_link(self):
     domain, id_with_ext = self.url.rsplit('/', 1)
     vidble_id, extension = id_with_ext.rsplit('.', 1)
     file_name = self.post_title if self.name_downloads_by == 'Post Title' else vidble_id
     x = Content(self.url, self.user, self.post_title, self.subreddit,
                 file_name, "", '.' + extension, self.save_path,
                 self.subreddit_save_method)
     self.extracted_content.append(x)
Example #21
0
 def _deletePage(self):
     if len(self.page.parent.pages) < 2:
         # We can't delete the last page
         return
     text = 'Text: [Empty]'
     if len(self.page.content) > 0:
         text = 'Text: \"' + self.page.content + '\"'
     if messagebox.askyesno('Delete Page?',
                            'Are you sure you want to delete page ' +
                            str(self.index + 1) + ' from entry \"' +
                            self.page.parent.parent.getPath() + '\"?\n\n' +
                            text,
                            default=messagebox.NO):
         self.page.parent.pages.pop(self.index)
         self.page.parent.parent.modified = True
         Content.markRestorePoint()
         self.rebuildcommand()
Example #22
0
 def _selectRegion(self, region):
     if region == newid:
         self.regionstring.set(Content.region)
         popup = PopupDialog(self.master,
                             title='New Region Id',
                             label='Id:',
                             validate=self._validateRegion)
         if popup.result:
             Content.region = popup.result
             Content.allregions.append(popup.result)
             self.regionstring.set(Content.region)
             self._rebuildOptions()
             Content.contentMutated()
         return
     if region != Content.region:
         Content.region = region
         Content.contentMutated()
Example #23
0
 def save(self, site, url):
     """Get text from url"""
     bs = self.getPage(url)
     if bs is not None:
         title = self.safeGet(bs, site.titleTag)
         if title != '':
             content = Content(url, title)
             return content.title, content.url
Example #24
0
 def toString(self, entryList=None):
     if entryList is None:
         entryList = self.getEntryList()
     
     outContent = Content()
     for entry in self.getEntryList(): 
         outContent.append(entry.toString())
     if outContent.getContentStr() is not None:
         outContent.append("")
     return outContent.getContentStr()
Example #25
0
class ImageFactory(object):
    def __init__(self):
        super(ImageFactory, self).__init__()
        self.path = None
        self.image = None
        self.gray = None
        self.feature_extractor = Projection()
        self.content_extractor = Content()
        self.content_list = None
        self.feature_list = np.array([])
        self.class_list = np.array([])
        # for display purpose
        self.display = None

    def initialize(self, path_to_image):
        self.path = path_to_image
        self.image = cv2.imread(self.path)
        self.gray = self.__prepare_image_gray()
        self.content_list = self.content_extractor.new_leuven_dichotomie(self.image, self.gray)
        # run extract_features
        self.extract_features()

    def extract_features(self):
        length = len(self.content_list)
        self.feature_list = np.zeros((length,500))
        for x in range(0, length):
            subImage_tmp = self.image[self.content_list[x][0][1]:self.content_list[x][1][1]+1, self.content_list[x][0][0]:self.content_list[x][1][0]+1]
            subGray_tmp = self.gray[self.content_list[x][0][1]:self.content_list[x][1][1]+1, self.content_list[x][0][0]:self.content_list[x][1][0]+1]
            self.feature_list[x] = self.feature_extractor.compute(subImage_tmp, subGray_tmp)
            pass
        pass

    def __prepare_image_gray(self):
        gray = cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY)
        height,width,channel = self.image.shape
        for x in range(0,width):
            gray[0][x] = 255
            gray[height-1][x] = 255
        for y in range(0,height):
            gray[y][0] = 255
            gray[y][width-1] = 255
        for y in range(0,height):
            for x in range(0,width):
                if gray[y][x] >= 250:
                    gray[y][x] = 255
                    pass
                pass
            pass
        return gray

    def draw(self):
        self.display = self.image.copy()
        for x in range(0,len(self.class_list)):
            if self.class_list[x][1] == 1:
                self.display[self.content_list[x][0][1]:self.content_list[x][1][1]+1, self.content_list[x][0][0]:self.content_list[x][1][0]+1, 0] += 100
        for x in range(0,len(self.content_list)):
            cv2.rectangle(self.display, self.content_list[x][0], self.content_list[x][1], (255, 0, 0), 1)
Example #26
0
 def __init__(self):
     self.content = Content()
     self.graphics_manager = GraphicsManager()
     self.input_manager = InputManager()
     self.running = False
     self.paused = False
     self.FPS = 30
     self.clock = pygame.time.Clock()
     self.entities = {}
 def extract_single(self):
     domain, gif_id = self.url.rsplit('/', 1)
     gfy_json = self.get_json(self.api_caller + gif_id)
     gfy_url = gfy_json.get('gfyItem').get('webmUrl')
     file_name = self.post_title if self.name_downloads_by == 'Post Title' else gif_id
     x = Content(gfy_url, self.user, self.post_title, self.subreddit,
                 file_name, "", '.webm', self.save_path,
                 self.subreddit_save_method)
     self.extracted_content.append(x)
 def extract_content(self):
     try:
         direct_link = "%s.jpg" % self.url
         x = Content(direct_link, self.user, self.post_title,
                     self.subreddit, self.post_title, "", '.jpg',
                     self.save_path, self.subreddit_save_method)
         self.extracted_content.append(x)
     except:
         self.extracted_content.append(
             "Failed to locate the content at %s\nUser: %s  Subreddit: %s  Title: %s"
             % (self.url, self.user, self.subreddit, self.post_title))
Example #29
0
def getcontents(filepath):
    #filename = "C:/Users/marco/Documents/GitHub/LexicalAnalyzer/main.txt"
    filename = filepath
    f = open(filename, "r")
    f1 = f.readlines()
    i = 1
    contents = []
    for line in f1:
        aux = Content()
        aux.content = line
        aux.line = i
        if (aux.content.startswith("//") == False):
            aux.content = aux.content.replace("\n", "")
            contents.append(aux)
        if (aux.content == ''):
            contents.pop()
        i = i + 1
    f.close()
    removecommentsblocks(contents)
    return contents
Example #30
0
    def from_db(collection, search_dict):
        db_sub = collection.find_one(search_dict)

        sub = Subreddit(collection, db_sub['type'], db_sub['name'], db_sub['dateCreated'], db_sub['deleted'],
                        [Content(**content) for content in db_sub['content']],
                        db_sub['subreddit']['rules'],
                        db_sub['subreddit']['mods'],
                        db_sub['subreddit']['subscribers'],
                        db_sub['subreddit']['numberSubscribers'],
                        ((creator[0], creator[1]) for creator in db_sub['subreddit']['creator']))
        sub._id = db_sub['_id']
        return sub
Example #31
0
    def __init__(self, master):
        self.master = master

        master.title("Dialogue Editor")
        master.geometry("1024x768")
        master.rowconfigure(1, weight=1)
        master.columnconfigure(1, weight=1)

        self._setupMenuBar(master)

        self.writer = FileWriter()

        Content.initData()
        Content.mutateEvent.append(self.refreshViews)

        self.toprow = TopRowMenu(master)
        self.paneltree = PanelTree(master)
        self.paneltext = PanelText(master)
        self.paneldetails = PanelDetails.PanelDetails(master)

        self.refreshViews()
Example #32
0
 def post(self):
   user = confirm(self)
   content = Content.get(self.request.get("content"))
   #calculate points
   from math import ceil
   cost = cost_of_content(content)
   logging.info("cost %d" % cost)
   from magic import get_magic
   magic_mod = get_magic()
   if user.points >= cost or magic_mod.freeleech:
       r = Request(user=user,file=content)
       r.put()
       if not magic_mod.freeleech:
           user.points -= int(cost)
           user.put()
       self.response.out.write("OK")
   else:
       self.response.out.write("NEEDMOREPOINTS %d" % (cost - user.points))
Example #33
0
class TableFactory(object):
    """docstring for TableFactory"""
    def __init__(self, path):
        super(TableFactory, self).__init__()
        self.path = path
        self.image = cv2.imread(self.path)
        self.image_display = self.image.copy()
        self.gray = self.__prepare_image_gray()
        self.gray_display = self.gray.copy()
        self.content_extractor = Content()
        self.tree_of_content = self.content_extractor.paris_dichotomie(self.image, self.gray)

    def __prepare_image_gray(self):
        gray = cv2.cvtColor(self.image, cv2.COLOR_BGR2GRAY)
        height,width,channel = self.image.shape
        for x in range(0,width):
            gray[0][x] = 255
            gray[height-1][x] = 255
        for y in range(0,height):
            gray[y][0] = 255
            gray[y][width-1] = 255
        for y in range(0,height):
            for x in range(0,width):
                if gray[y][x] >= 250:
                    gray[y][x] = 255
                    pass
                pass
            pass
        return gray

    def serialize(self):
        pass

    def deserialize(self):
        pass

    def drawing_image_cv2(self):
        self.image_display = self.image.copy()
        self.tree_of_content.display_only_leaf_cv2(self.image_display)
Example #34
0
    def __init__(self, main, filename):
        xml.sax.handler.ContentHandler.__init__(self)

        self.filename = filename
        self.__content = Content()
        self.depth = 0
        self.unsecure = main.unsecure
        self.main = main

        self.last_page = None
        self.last_item = None
        self.last_group = None
        self.last_tag = None

        self.current_tag = None

        self.aliases = self.__content.cssalias
        self.styles = self.__content.cssclass
        self.contentchars = None
        self.currentimageid = None

        import re
        self.re_css_class = re.compile(r'^\s*?(\S+)\s*\{(\s*.+?\s*)\}(.*)$', re.S)
        self.re_css_comments = re.compile(r'/\*.*?\*/', re.S)
Example #35
0
 def get(self):
   results = Content.all().order("-shared_date").fetch(limit=25)
   self.response.out.write(print_results(results))
 def __init__(self):
     Content.__init__(self, 'empty')
Example #37
0
class ContentParser(xml.sax.handler.ContentHandler):
    def __init__(self, main, filename):
        xml.sax.handler.ContentHandler.__init__(self)

        self.filename = filename
        self.__content = Content()
        self.depth = 0
        self.unsecure = main.unsecure
        self.main = main

        self.last_page = None
        self.last_item = None
        self.last_group = None
        self.last_tag = None

        self.current_tag = None

        self.aliases = self.__content.cssalias
        self.styles = self.__content.cssclass
        self.contentchars = None
        self.currentimageid = None

        import re
        self.re_css_class = re.compile(r'^\s*?(\S+)\s*\{(\s*.+?\s*)\}(.*)$', re.S)
        self.re_css_comments = re.compile(r'/\*.*?\*/', re.S)

    def showerror(self, exception, text):
        linenumber = self.locator.getLineNumber()
        columnnumber = self.locator.getColumnNumber()

        # open the file and print the error line
        try:
            f = open(self.filename)
        except IOError:
            pass
        else:
            import sys
            lines = f.readlines()

            s = max(1, linenumber - 3)
            while s < linenumber:
                sys.stderr.write('%5d %s' % (s, lines[s-1]))
                s += 1

            sys.stderr.write('\033[1;31m%5d\033[m %s' % (s, lines[s-1]))
            s += 1

            t = min(linenumber + 3, len(lines)) + 1
            while s < t:
                sys.stderr.write('%5d %s' % (s, lines[s-1]))
                s += 1

            sys.stderr.write('\n')

        # raise the exception
        raise exception, '%s:%d:%d: %s' % \
            (self.filename, linenumber, columnnumber, text)

    def error(self, exception):
        self.showerror(InvalidXML, exception.args[0])

    fatalError = error

    def setDocumentLocator(self, locator):
        self.locator = locator

    def getlocation(self):
        l = self.locator
        return '%d:%d:' % (l.getLineNumber(), l.getColumnNumber())

    def startElement(self, name, xml_attrs):
        self.depth += 1
        self.current_tag = name

        # Copy the attributes into a dictionary
        attrs = {}
        for key, val in xml_attrs.items(): attrs[key] = val

        if name == 'presentation':
            if self.depth != 1:
                self.showerror(InvalidXML, 'The root node has to be <presentation>')

            # Save the presentation attributes.
            self.__content.set_attrs(attrs)

        elif name == 'page':
            if self.depth != 2:
                self.showerror(InvalidXML, '<page> has to be a child of the root node')

            self.last_page = self.__content.add_page(attrs)

        elif name == 'group':
            if self.depth != 3:
                self.showerror(InvalidXML, '<group> has to be a child of a page')

            self.last_group = self.last_page.add_group([])
            self.last_group.attrs = attrs

        elif name == 'style':
            # limited support for CSS.
            if attrs.has_key('source'):
                # load and external file
                try:
                    self.contentchars = open(attrs['source']).read()
                except IOError, e:
                    self.showerror(InvalidCSS, 'Unable to load the file: ' + str(e))
            else:
                self.contentchars = ''

        elif name == 'defimage':
            try:
                self.currentimageid = attrs['id']
            except KeyError:
                self.showerror(InvalidXML, 'You have to put an id for <defimage>')

            self.contentchars = ''
 def __init__(self, name, posX, posY):
     Content.__init__(self, name)
     self.next
     self.posX = posX
     self.posY = posY
Example #39
0
 def get(self):
     results = Content.all().search(self.request.get("query")).fetch(limit=6)
     self.response.out.write(print_results(results))