Ejemplo n.º 1
0
    def __init__(self, version):
        """Instantiate a manager for a particular wiki version.
        This sets up a connection to the wiki, fetches Airtable API key and defines which tables
        in the Airtable database have their templates defined.

        Args:
            version (str): wiki version to interface with (official or test)
        """
        with open('config.json', 'r') as f:
            config = json.load(f)
        if version not in ["official", "test"]:
            print(
                'Unknown version specified, choose from: "official" or "test".'
            )
            return
        else:
            self.wiki = dw.DokuWiki(
                config[version]["wiki_url"], config[version]["username"],
                os.environ[config[version]["password_key"]])
            self.user_key = os.environ['AIRTABLE_API_KEY']
            self.table = None
            self.used_table_name = None
            self.defined_tables = [
                'Tools', 'ftse100+givingpolicies', 'Categories',
                'Charity experiments', 'Experiences', 'Third sector',
                'papers_mass'
            ]
Ejemplo n.º 2
0
 def __init__(self, url, wikiuser, wikipass, nice_url="none"):
     """
     Constructor method for class Wiki
     
     Args:
         url (str): Base url of the DokuWiki installation
         wikiuser (str): Login username
         wikipass (str): Login password
         nice_url (str): dokuwiki nice url setting. Valid values: "none", "internal", "htaccess"
     
     Raises:
         err: exceptions that occurred while accessing the wiki
     """
     try:
         self.wiki = dokuwiki.DokuWiki(url, wikiuser, wikipass)
     except dokuwiki.DokuWikiError as err:
         raise err
     if nice_url == "none":
         self.baseurl = join_url([url, "doku.php?id="])
     elif nice_url == "internal":
         self.baseurl = join_url([url, "doku.php/"])
     elif nice_url == "htaccess":
         self.baseurl = join_url([url], trailing_slash=True)
     else:
         self.baseurl = join_url([url, "doku.php?id="])
Ejemplo n.º 3
0
    def __init__(self, token, dokuwiki_creds=None):
        self.token = token
        self.api_url = "https://api.telegram.org/bot{}/".format(token)
        self.scheduled_tasks = {}
        self.help_menu = ("Let me help you:\n"
                          "/start\n"
                          "/hi\n"
                          "/mpoll,<question>,<answer1>,<answers2>,...\n"
                          "/poll,<question>,<answer1>,<answers2>,...\n"
                          "/search,<search>")

        if dokuwiki_creds:
            try:
                self.dokuwiki_url = dokuwiki_creds.get("url")
                self.dokuwiki = dokuwiki.DokuWiki(
                    dokuwiki_creds.get("url"),
                    dokuwiki_creds.get("user", ""),
                    dokuwiki_creds.get("password", ""),
                    cookieAuth=True,
                )
            except (dokuwiki.DokuWikiError, Exception) as error:
                print(f"Unable to connect to Dokuwiki with error {error}")

        # Emoji faces have to be encoded in unicode to be display in Telegram chat
        self.emoji = {
            ":grinning:": "\U0001F600",
            ":joy:": "\U0001F602",
            ":rolling_laughing:": "\U0001F923",
            ":wink:": "\U0001F609",
            ":zany_face:": "\U0001F92A",
        }
Ejemplo n.º 4
0
def run_tests():
    args = parser.parse_args()

    integration_tests_config = yaml.load(
        open(args.yaml_filepath), Loader=yaml.CLoader
    )
    doku_conn = dokuwiki.DokuWiki(
        url=integration_tests_config["dokuwiki"]["url"],
        user=integration_tests_config["dokuwiki"]["username"],
        password=integration_tests_config["dokuwiki"]["password"],
    )
    less_packets = "--less-packets" if args.less_packets else ""
    test_command = [
        "python",
        "setup.py",
        "test",
        "--test-path=tardis/tests/integration_tests/test_integration.py",
        "--args",
        f"--capture=no --integration-tests={args.yaml_filepath} --tardis-refdata={args.tardis_refdata} --remote-data "
        f"{less_packets}",
    ]
    subprocess.call(test_command)

    while True:
        # Request Github API and get githash of master on Github.
        gh_request = requests.get(
            "https://api.github.com/repos/tardis-sn/tardis/branches/master"
        )
        gh_master_head_data = json.loads(gh_request.content)
        gh_tardis_githash = gh_master_head_data["commit"]["sha"][:7]

        # Check whether a report of this githash is uploaded on dokuwiki.
        # If not, then this is a new commit and tests should be executed.
        dokuwiki_report = doku_conn.pages.get(
            f"reports:{gh_tardis_githash}"
        )

        # If dokuwiki returns empty string, then it means that report has not
        # been created yet.
        if len(dokuwiki_report) == 0:
            subprocess.call(
                [
                    "git",
                    "pull",
                    "https://www.github.com/tardis-sn/tardis",
                    "master",
                ]
            )
            subprocess.call(test_command)
        else:
            checked = datetime.datetime.now()
            logger.info(
                f"Up-to-date. Checked on {checked.strftime('%d-%b-%Y')} {checked.strftime('%H:%M:%S')}"
            )
            time.sleep(600)
Ejemplo n.º 5
0
    def __init__(self, report_config):
        """
        Initialization of a DokuReport object and registration as a plugin
        occurs in `pytest_configure`, where a dict containing url, username and
        password of dokuwiki is passed through `dokuwiki_details`.
        """
        # This will be either "remote" or "local".
        self.save_mode = report_config["save_mode"]

        if self.save_mode == "remote":
            import dokuwiki

            # Base class accepts a file path to save the report, but we pass an
            # empty string as it is redundant for this use case.
            super(DokuReport, self).__init__(
                logfile=" ", self_contained=True, has_rerun=False
            )

            # Upload the report on a dokuwiki instance.
            dokuwiki_details = report_config["dokuwiki"]
            try:
                self.doku_conn = dokuwiki.DokuWiki(
                    url=dokuwiki_details["url"],
                    user=dokuwiki_details["username"],
                    password=dokuwiki_details["password"],
                )
            except (TypeError, gaierror, dokuwiki.DokuWikiError) as e:
                raise e
                self.doku_conn = None
                self.dokuwiki_url = ""
            else:
                self.dokuwiki_url = dokuwiki_details["url"]
        else:
            # Save the html report file locally.
            self.report_dirpath = os.path.join(
                os.path.expandvars(
                    os.path.expanduser(report_config["reportpath"])
                ),
                tardis_githash[:7],
            )

            if os.path.exists(self.report_dirpath):
                shutil.rmtree(self.report_dirpath)
            os.makedirs(self.report_dirpath)
            os.makedirs(os.path.join(self.report_dirpath, "assets"))

            super(DokuReport, self).__init__(
                logfile=os.path.join(self.report_dirpath, "report.html"),
                self_contained=False,
                has_rerun=False,
            )

        self.suite_start_time = time.time()
Ejemplo n.º 6
0
def create_wiki_session():
    """returns dokuwiki session, aiming for safer experience"""
    print(crayons.yellow("Enter credentials for {}".format(WIKI_URL)))
    user = input("User: "******"Password: "******"Connected to {}".format(wiki.title)))
        return wiki
Ejemplo n.º 7
0
def run_tests():
    args = parser.parse_args()

    integration_tests_config = yaml.load(open(args.yaml_filepath))
    doku_conn = dokuwiki.DokuWiki(
        url=integration_tests_config['dokuwiki']['url'],
        user=integration_tests_config['dokuwiki']['username'],
        password=integration_tests_config['dokuwiki']['password']
    )
    less_packets = "--less-packets" if args.less_packets else ""
    test_command = [
        "python", "setup.py", "test",
        "--test-path=tardis/tests/integration_tests/test_integration.py", "--args",
        "--capture=no --integration-tests={0} --atomic-dataset={1} --remote-data "
        "{2}".format(args.yaml_filepath, args.atomic_dataset, less_packets)
    ]
    subprocess.call(test_command)

    while True:
        # Request Github API and get githash of master on Github.
        gh_request = requests.get(
            "https://api.github.com/repos/tardis-sn/tardis/branches/master"
        )
        gh_master_head_data = json.loads(gh_request.content)
        gh_tardis_githash = gh_master_head_data['commit']['sha'][:7]

        # Check whether a report of this githash is uploaded on dokuwiki.
        # If not, then this is a new commit and tests should be executed.
        dokuwiki_report = doku_conn.pages.get(
            "reports:{0}".format(gh_tardis_githash)
        )

        # If dokuwiki returns empty string, then it means that report has not
        # been created yet.
        if len(dokuwiki_report) == 0:
            subprocess.call([
                "git", "pull", "https://www.github.com/tardis-sn/tardis", "master"
            ])
            subprocess.call(test_command)
        else:
            checked = datetime.datetime.now()
            logger.info("Up-to-date. Checked on {0} {1}".format(
                checked.strftime("%d-%b-%Y"), checked.strftime("%H:%M:%S")
            ))
            time.sleep(600)
Ejemplo n.º 8
0
def wiki_news():
    """Returns list of last week WikiNews object"""
    result = []
    wiki = dokuwiki.DokuWiki("http://sisarqwiki.corp.cablevision.com.ar",
                             login["user"], login["password"])
    changes = wiki.pages.changes(int(time.time() - 604800))
    for value in changes:
        print(value["lastModified"])
        if ":" in value["name"]:
            new = WikiNews(name=value["name"].split(":")[-1],
                           last_modified=str(
                               value["lastModified"]).split("T")[0],
                           author=value["author"])
        else:
            new = WikiNews(name=value["name"],
                           last_modified=str(
                               value["lastModified"]).split("T")[0],
                           author=value["author"])
        result.append(new)
    return result
Ejemplo n.º 9
0
# -*- coding: UTF-8 -*-
import dokuwiki
from dokuwiki import DokuWikiError
import urllib
from urllib import error
from urllib import request

WIKI_URL = "http://itbaike.contoso.com"
FULL_TEXT_SEARCH_KEY = "outlook"
RPCUser = "******"
Pwd = "P@ssw0rd"

try:
    wiki = dokuwiki.DokuWiki(WIKI_URL + "/wiki", RPCUser, Pwd)
except (DokuWikiError, Exception) as err:
    print('unable to connect: %s' % err)

Pages = wiki.pages
SearchResult = Pages.search(FULL_TEXT_SEARCH_KEY)

ResultPages = []

try:
    for i in range(len(SearchResult)):
        print(SearchResult[i]['id'])
        html = request.urlopen(
            WIKI_URL + "/wiki/doku.php?id=" +
            urllib.parse.quote(SearchResult[i]['id'])).read().decode("utf-8")
        ResultPages.append(html)
        html = ""
except error.HTTPError as e:
Ejemplo n.º 10
0
def create_connection(username, password):
    return dokuwiki.DokuWiki('https://ocw.cs.pub.ro/courses',
                             username,
                             password,
                             cookieAuth=True)
Ejemplo n.º 11
0
import sys
import dokuwiki
from lib.google_sheets import GoogleSheets
from lib.shop import Shop
import subprocess

if __name__ == '__main__':
    try:
        from config.mywiki import *
        from config.shop_sheet import *
    except ModuleNotFoundError:
        print('找不到config')
        sys.exit()

    try:
        wiki = dokuwiki.DokuWiki(siteurl, username, password, True)
    except dokuwiki.DokuWikiError:
        print('Username or password is wrong ,can\'t access wiki')
        sys.exit()

    # Set sheet instance
    shop_sheet = GoogleSheets()
    shop_sheet.sheet_id = SPREADSHEET_ID
    shop_sheet.range = RANGE_NAME
    # pull data
    shop_sheet.pull_data()
    shop_list = shop_sheet.dict_list

    # Set sheet instance
    qiyue_sheet = GoogleSheets()
    qiyue_sheet.sheet_id = SPREADSHEET_ID
Ejemplo n.º 12
0
"""

airtablefetcher = airtable_fetcher.AirtableFetcher(userkey)

tools_dict = airtablefetcher.fetch_table_and_records(basekey_giving_researchers_shared, tools_sample)
tools_records = tools_dict['records']

theories_dict = airtablefetcher.fetch_table_and_records(basekey_giving_researchers_shared, theories, ['Theory'])
theories_table = theories_dict['table']
theories_records = theories_dict['records']

"""
Initialize the wiki object
"""

wiki = dokuwiki.DokuWiki(url, usr, pss)


# STAND ALONE FUNCTION TO BE ENCAPSULATED LATER

def tool_row_constructor(record):
    """
    Construct a row for the tools table based on data delivered by Airtable.
    :param record: a single record from the Airtable
    :return: a formatted row for DW
    """
    tool_name = record['fields']['Toolname']
    page_name= tool_name.translate(punctuation_translator)
    tool_page_name = '[[iifwiki:tools:{}|{}]]'.format(page_name, tool_name)

    category = record['fields'].get('Category', [""])
            b.click()
            break
    else:
        raise ValueError("Could not find rename button")

    redirect_content = "This Page was moved to [[{}]] in a different namespace.".format(name_new)

    dw.pages.set(name_old, redirect_content)

    print("old url: ", url)


with open(resfilepath) as txtfile:
    file_map_list = txtfile.readlines()

dw = dokuwiki.DokuWiki(wikiurl, user_name, user_pw)

if 0:
    delete_all_pages()
    add_old_pages_for_testing()

driver = webdriver.Firefox()
perform_login()

for idx in range(len(file_map_list)):
    rename_page(idx)


# IPS()