Beispiel #1
0
def interest():
    # get the user's tags
    userTags = Tag().user_tags(graph_db,
                               request.get_cookie(graphstoryUserAuthKey))
    # get the tags of user's friends
    tagsInNetwork = Tag().tags_in_network(
        graph_db, request.get_cookie(graphstoryUserAuthKey))

    # if the user's content was requested
    if request.query.get('userscontent') == "true":
        contents = Content().get_user_content_with_tag(
            graph_db, request.get_cookie(graphstoryUserAuthKey),
            request.query.get('tag'))
    # if the user's friends' content was requested
    else:
        contents = Content().get_following_content_with_tag(
            graph_db, request.get_cookie(graphstoryUserAuthKey),
            request.query.get('tag'))

    return template('public/templates/graphs/interest/index.html',
                    layout=applayout,
                    userTags=userTags,
                    tagsInNetwork=tagsInNetwork,
                    contents=contents,
                    title="Interest")
Beispiel #2
0
    def parse(self, response):
        items = []

        # Extract each row/item/"thing" in the reddit feed
        for entry in response.css('div.thing'):
            # Extract the title
            title = entry.css("p.title > a::text").extract_first()

            # Get the URL to the comments
            # comments_url = entry.css(TODO).extract_first()

            # Get the URL to the submission
            url = entry.css("p.title > a::attr(href)").extract_first()

            # Get the score of the post
            score = entry.css(".score.unvoted::text").extract_first()
            if score == "•":
                score = None
            elif "k" in score:
                score = int(float(score[:-1]) * 1000)
            else:
                score = int(score)

            content = Content(source="reddit",
                              title=title,
                              url=url,
                              score=score)
            items.append(content)

        self.save_many(items)
Beispiel #3
0
    def GET(self, path=None, reply=None):
        if not path:
            path = conf.navigation.default_slug
            return PrettyRedirect('/' + path)
        (slug, ext) = splitext(path)
        ext = ext.lower()

        if not reply:
            reply = reply_form()

        if ext in PASSTHROUGH_EXTENSIONS:
            try:
                return open(join(conf.siteopts.root, path)).read()
            except IOError:
                return web.notfound()

        if os.path.isdir(join(conf.siteopts.root, slug)):
            return render.multiple_pages('Posts in ' + slug,
                                         get_gtf_in_slug(slug))

        try:
            content = Content(slug)
            return render.single_page(content, reply)
        except IOError:
            raise web.notfound()
Beispiel #4
0
def index(pagenum):
    contentsAsJson = Content().content_results_as_list(
        graph_db, request.get_cookie(graphstoryUserAuthKey), pagenum)

    response.content_type = 'application/json'

    return dumps(contentsAsJson)
 def setup_content_item_image_cat(self):
     tags = ["kitty", "kitten", "cat", "cute", "pet", "cutie", "animals"]
     content = Content("telegram", "@image_cat", tags, application="cats")
     image = ContentImage("image", "random", self.mockinfo.mockdirwfiles,
                          False, "json", self.mockinfo.historyfile)
     content.add_content_item(image)
     return content
Beispiel #6
0
    def __init__(self, master):
        # Prevent the app window from being resized
        master.resizable(False, False)
        self.banner = Banner(master)
        self.content = Content(master)

        # KEYBOARD SHORTCUTS SECTION
        master.bind('<Control-n>', lambda e: self.content.add_task())

        # MENU BAR SECTION
        master.option_add('*tearOff', False)
        self.menubar = Menu(master)
        master.config(menu=self.menubar)

        # FILE MENU
        file = Menu(self.menubar)
        file.add_command(label='Test',
                         command=lambda: messagebox.showinfo(
                             title='Test', message='This is a test.'))
        file.add_command(label='Add Task',
                         command=lambda: self.content.add_task())
        file.entryconfig('Add Task', accelerator='CTRL+N')
        self.menubar.add_cascade(menu=file, label='File')

        # EDIT MENU
        edit = Menu(self.menubar)
        edit.add_command(label='Change Banner Color',
                         command=lambda: self.banner.change_banner_color())
        self.menubar.add_cascade(menu=edit, label='Edit')
Beispiel #7
0
def make_cheatsheet(driver):
    usernames = get_all_users(driver)

    targets = {}
    for name in usernames:
        first, second, *rest = name.split(' ')
        key = first.upper()[:2]
        if second:
            key += second.upper()[0]
        else:
            key = first[2].upper()
        count = 0
        while key in targets:
            if count:
                key = key[:-1] + str(count)
            else:
                key += '1'
            count += 1
        targets[key] = name

    # This is for sending to Master group for reference
    item = Content()
    item.set_type('text')
    msg = ""
    for key, value in sorted(targets.items()):
        msg += "{:<15} {:<15}\n".format(key, value)

    item.set_content(message=msg)
    return targets, item
Beispiel #8
0
    def parse(self, response):
        # TODO: Might want to use RSS feed instead
        items = []

        # HN has a weird table account:
        #  - Every (n*3)th line is a title
        #  - Every (n*3+1)th line is a subtitle (that contains the score)
        entries = response.css('table.itemlist > tr')
        for i in range(0, len(entries), 3):
            # Extract the title
            title = entries[i + 0].css("td.title > a::text").extract_first()
            if title is None:
                # FIXME: Prevent this from happening in the first place
                # Something went wrong, skip
                continue

            # Extract the URL to the submission
            url = entries[i + 0].css("td.title > a::attr(href)").extract_first()

            # Extract the score of the post
            score = entries[i + 1].css("td > span.score::text").extract_first()
            if score:
                score = int(score.split()[0])

            content = Content(source="hn", title=title, url=url, score=score)

            items.append(content)

        self.save_many(items)
 def setup_content_item_text(self):
     content = Content("telegram", "@quotes_literature", "",
             application="quotes")
     format_rules = [{"\"%s":0},{"\"\n\n- %s":1}]
     text = ContentText("text", "random", "database",
                        self.mockinfo.mockdb, format_rules, "")
     content.add_content_item(text)
     return content
Beispiel #10
0
    def test_rename_is_not_called_when_folder_is_empty(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()

        content.rename('a', 'b')

        mock_terminal.move.assert_not_called()
Beispiel #11
0
    def test_copy_is_not_started_when_folder_is_empty(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()

        content.copy_selected()

        self.assertEqual('', content.path_to_copy)
Beispiel #12
0
    def test_delete_is_not_called_when_folder_is_empty(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()

        content.delete_selected()

        mock_terminal.delete.assert_not_called()
Beispiel #13
0
def init():
    global plc, cont, db, refresh, maxpos, showpos
    db = Database()
    plc = Plc(db)
    cont = Content(plc)
    refresh = False
    maxpos = 999999
    showpos = maxpos
    def test_rename_is_called_with_correct_absolute_paths(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()

        content.rename('aaaa', 'bbbb')

        mock_terminal.move.aassert_called_with(cwd + 'aaaa', cwd + 'bbbb')
Beispiel #15
0
 def __init__(self, ngram, dir):
     self.docID = DocID()
     self.tokenizer = Tokenizer("ma")
     self.content = Content()
     self.ngram = ngram
     self.docID.load(dir + "docid.pickle")
     self.content.load(dir + "content.pickle")
     self.stopwords = self._load_stopwords(STOPWORDS_FILE)
Beispiel #16
0
def viewpost(contentId):
    statusupdate = Content().get_status_update(
        graph_db, request.get_cookie(graphstoryUserAuthKey), contentId)

    return template('public/templates/graphs/social/post.html',
                    layout=applayout,
                    content=statusupdate,
                    title=statusupdate[0].title)
Beispiel #17
0
 def __init__(self):
     self.content = Content()
     self.db = MysqlControl()
     self._RST_RE = re.compile(r'\d+')
     self._ID_RE0 = re.compile(r'shopId:\s*(\d+)')
     self._ID_RE1 = re.compile(r'shopID:\s*(\d+)')
     self._NAME_RE = re.compile(r'cityCnName:\s*"(\S+)"')
     self._PHONE_RE = re.compile(r'电话:</span>\s+.+tel">(\d{3,4}.\d+)')
     self._REPLY_RE = re.compile(r'J-busi-reply')
    def test_open_terminal_is_called_with_cwd(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()
        content.main_pane_selected_line_i = 0

        content.open_new_terminal()

        mock_terminal.open_new_terminal.assert_called_with(content.cwd)
Beispiel #19
0
def get_gtf_in_slug(slug):
  for root, dirs, files in os.walk(join(conf.siteopts.root, slug)):

    # Don't go into . directories
    filter(lambda d: not d.startswith('.'), dirs)
    
    for f in files:
      if f.lower().endswith('.gtf'):
        yield Content(slug_from_path(join(root, f)))
Beispiel #20
0
    def __init__(self, standard_screen):
        self.is_working = True
        self.standard_screen = standard_screen
        curses.curs_set(False)
        curses.init_pair(2, curses.COLOR_CYAN, curses.COLOR_BLACK)

        self.content = Content()
        self.input_keys = InputKeys()
        self.pane_manager = PaneManager(standard_screen)
Beispiel #21
0
 def __init__(self, url, casperJSScript='pastebintext.js'):
     threading.Thread.__init__(self)
     self.url = url
     self.casperJSScript = casperJSScript
     self.content = Content()
     self.data = []
     rua = Random_user_agent()
     self.ua = rua.rand()
     self.result = None
    def test_delete_calls_delete_with_child_path(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()
        content.main_pane_selected_line_i = 0

        content.delete_selected()

        mock_terminal.delete.assert_called_with(cwd + 'aaaa')
Beispiel #23
0
def sweep_get_content():
    sweep = SweepElement(key="sweep",
                         title="Frequency sweep",
                         default_datatype="src_data")

    cnt = Content()
    cnt.add(sweep, position=(0, 0))

    return cnt
Beispiel #24
0
    def parseContents(self):
        contentParts = self.getAllPartsWithName('content')

        contents = []

        for contentPart in contentParts:
            contents.append(Content(contentPart))

        return contents
    def test_first_not_hidden_line_is_selected_after_hiding_hidden_files(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()
        content.main_pane_selected_line_i = 0
        content.show_hidden = True

        content.toggle_show_hidden()

        self.assertEqual(0, content.main_pane_selected_line_i)
Beispiel #26
0
    def __init__(self, parent, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        self.parent = parent
        self.parent.title('todo.txt')

        self.content = Content(self)
        self.content.grid(row=0, column=0, sticky='nsew')

        self.settings = Settings(self, self.content)
        self.parent.configure(menu=self.settings)
 def write(self, frame, content=None):
     if self._closed:
         raise Closed(self.reason)
     frame.channel = self.id
     self.outgoing.put(frame)
     if (isinstance(frame, (Method, Request)) and content == None
             and frame.method_type.content):
         content = Content()
     if content != None:
         self.write_content(frame.method_type.klass, content)
    def test_copy_changes_path_to_copy_and_copy_removes_source(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()
        content.main_pane_selected_line_i = 0

        content.copy_selected()

        self.assertEqual(cwd + 'aaaa', content.path_to_copy)
        self.assertFalse(content.copy_removes_source)
    def test_new_folder_calls_make_new_folder_with_name(self, mock_terminal):
        mock_terminal.provide_initial_cwd.return_value = cwd
        mock_terminal.get_ls.side_effect = mock_return_values
        content = Content()
        content.main_pane_selected_line_i = 0

        folder_name = 'new_folder_name'
        content.make_new_folder(folder_name)

        mock_terminal.make_new_folder.assert_called_with(cwd + folder_name)
Beispiel #30
0
 def parse(self, site, url):
     """
     Extract content from a given page URL
     """
     bs = self.get_page(url)
     if bs is not None:
         title = self.safe_get(bs, site.titleTag)
         body = self.safe_get(bs, site.bodyTag)
         if title != '' and body != '':
             content = Content(url, title, body)
             content.print()