コード例 #1
0
class MyGist:
    def __init__(self, name, description, content, username="", api_token=""):
        self.name = name
        self.description = description
        self.content = content
        self.gist_connection = Simplegist(username=username,
                                          api_token=api_token)
        gist_info = self.gist_connection.create(name=self.name,
                                                description=self.description,
                                                public=True,
                                                content=self.content)
        self.gist_link = gist_info["Gist-Link"]
        self.url = self.gist_link
        self.clone_link = gist_info["Clone-Link"]
        self.embed_script = gist_info["Embed-Script"]
        self.id = gist_info["id"]
        self.created_at = gist_info['created_at']

    def update(self, name=None, description=None, content=None):
        if name is not None:
            self.name = name
        if description is not None:
            self.description = description
        if content is not None:
            self.content = content
        self.gist_connection.profile().edit(id=self.id,
                                            description=self.description,
                                            name=self.name,
                                            content=self.content)
コード例 #2
0
ファイル: history.py プロジェクト: lthomas4912/Navi-Slackbot
def add_link(message, channel_id):
    gist = Simplegist(username='******',
                      api_token=os.environ["GIST_ACCESS_TOKEN"])
    keys = json.loads(gist.profile().content(id=gist_list_id))[channel_id]
    new_links: List[Link] = parse_link_or_attachment(message)
    total_links = generate_json(keys[0], new_links)
    # updates the markdown
    gist.profile().edit(id=keys[1],
                        content=generate_md_file(total_links, channel_id))
コード例 #3
0
ファイル: history.py プロジェクト: lthomas4912/Navi-Slackbot
def generate_json(gist_id, new_links):
    gist = Simplegist(username='******',
                      api_token=os.environ["GIST_ACCESS_TOKEN"])
    json_data = json.loads(gist.profile().content(id=gist_id))
    old_links = {
        category: [Link.from_json(link) for link in links]
        for category, links in json_data.items()
    }
    total_links = merge_dicts([old_links, sort_into_sections(new_links)])
    json_data = {
        category: [link.to_json() for link in links]
        for category, links in total_links.items()
    }
    # updates the json
    gist.profile().edit(id=gist_id, content=json.dumps(json_data))
    return total_links
コード例 #4
0
 def __init__(self, name, description, content, username="", api_token=""):
     self.name = name
     self.description = description
     self.content = content
     self.gist_connection = Simplegist(username=username,
                                       api_token=api_token)
     gist_info = self.gist_connection.create(name=self.name,
                                             description=self.description,
                                             public=True,
                                             content=self.content)
     self.gist_link = gist_info["Gist-Link"]
     self.url = self.gist_link
     self.clone_link = gist_info["Clone-Link"]
     self.embed_script = gist_info["Embed-Script"]
     self.id = gist_info["id"]
     self.created_at = gist_info['created_at']
コード例 #5
0
def add_link(message, channel_id):
    gist = Simplegist(username='******',
                      api_token=os.environ["GIST_ACCESS_TOKEN"])
    keys = json.loads(gist.profile().content(id=gist_list_id))[channel_id]
    json_data = json.loads(gist.profile().content(id=keys[0]))
    sectioned_links = {
        category: [Link.from_json(link) for link in links]
        for category, links in json_data.items()
    }
    new_links: List[Link] = parse_link_or_attachment(message)
    sectioned_links = add_to_section(new_links, sectioned_links)
    json_data = {
        category: [link.to_json() for link in links]
        for category, links in sectioned_links.items()
    }
    gist.profile().edit(id=keys[0], content=json.dumps(json_data))
    gist.profile().edit(id=keys[1],
                        content=generate_md_file(sectioned_links, channel_id))
コード例 #6
0
def get_history(channel_id):
    gist = Simplegist(username='******',
                      api_token=os.environ["GIST_ACCESS_TOKEN"])
    sectioned_links = get_links(get_messages(channel_id))
    json_file = gist.create(name=get_channel_name(channel_id) + ".json",
                            description="json for channel links",
                            content=json.dumps(original_json(sectioned_links)))
    md_file = gist.create(name=get_channel_name(channel_id) + ".md",
                          description="Collected links of channel",
                          content=generate_md_file(sectioned_links,
                                                   channel_id))
    keys = json.loads(gist.profile().content(id=gist_list_id))
    keys[channel_id] = [json_file['id'], md_file['id']]
    gist.profile().edit(id=gist_list_id, content=json.dumps(keys))
    return md_file['Gist-Link']
コード例 #7
0
ファイル: history.py プロジェクト: lthomas4912/Navi-Slackbot
def get_history(channel_id):
    gist = Simplegist(username='******',
                      api_token=os.environ["GIST_ACCESS_TOKEN"])
    total_links = merge_dicts(get_all_links(channel_id))
    json_data = {
        category: [link.to_json() for link in links]
        for category, links in total_links.items()
    }
    # updates the json
    json_file = gist.create(name=get_channel_name(channel_id) + ".json",
                            description="json for channel links",
                            content=json.dumps(json_data))
    md_file = gist.create(name=get_channel_name(channel_id) + ".md",
                          description="Collected links of channel",
                          content=generate_md_file(total_links, channel_id))
    keys = json.loads(gist.profile().content(id=gist_list_id))
    keys[channel_id] = [json_file['id'], md_file['id']]
    gist.profile().edit(id=gist_list_id, content=json.dumps(keys))
    generate_findall()
    return md_file['Gist-Link']
コード例 #8
0
ファイル: history.py プロジェクト: lthomas4912/Navi-Slackbot
def get_link_to_links(channel_id):
    gist = Simplegist(username='******',
                      api_token=os.environ["GIST_ACCESS_TOKEN"])
    keys = json.loads(gist.profile().content(id=gist_list_id))
    return f"https://gist.github.com/ElBell/{keys[channel_id][1]}"
コード例 #9
0
ファイル: history.py プロジェクト: lthomas4912/Navi-Slackbot
def generate_findall():
    gist = Simplegist(username='******',
                      api_token=os.environ["GIST_ACCESS_TOKEN"])
    keys = json.loads(gist.profile().content(id=gist_list_id))
    gist.profile().edit(id=gist_find_all, content=generate_findall_md(keys))