def test_set_user_agent(self): orig = requests.utils.default_user_agent requests.utils.default_user_agent = lambda: 'python-requests/2.13.0' expected = 'mycooltool (https://tools.wmflabs.org/mycooltool; ' +\ '[email protected]) python-requests/2.13.0' ret = toolforge.set_user_agent('mycooltool') self.assertEqual(ret, expected) self.assertEqual( requests.get('https://httpbin.org/user-agent').json(), {'user-agent': expected} ) requests.utils.default_user_agent = orig
from flask import Flask, request, render_template from flask_caching import Cache import re import requests import operator import toolforge app = Flask(__name__) cache = Cache(app, config={ 'CACHE_TYPE': 'redis', 'CACHE_REDIS_HOST': 'tools-redis', 'CACHE_KEY_PREFIX': 'tool-checker' }) toolforge.set_user_agent('checker') @cache.cached(timeout=60 * 60 * 24) def database_list(): conn = toolforge.connect('meta_p') cursor = conn.cursor() cursor.execute(''' /* checker.py database_list */ SELECT dbname FROM wiki WHERE is_closed = 0 ORDER BY dbname ASC; ''') databases = cursor.fetchall()
import decorator import flask import mwapi # type: ignore import os import random import stat import string import toolforge from typing import Any, Callable import yaml from pagepile import load_pagepile, create_pagepile app = flask.Flask(__name__) user_agent = toolforge.set_user_agent('pagepile-visual-filter', email='*****@*****.**') @decorator.decorator def read_private(func: Callable, *args: Any, **kwargs: Any) -> Any: try: f = args[0] fd = f.fileno() except AttributeError: pass except IndexError: pass else: mode = os.stat(fd).st_mode if (stat.S_IRGRP | stat.S_IROTH) & mode: name = getattr(f, "name", "config file")
import flask import mwapi import mwoauth import os import random import requests_oauthlib import string import toolforge import yaml import json import mwparserfromhell app = flask.Flask(__name__) user_agent = toolforge.set_user_agent('musikverket-description-translations', email='*****@*****.**') target_instance = 'https://commons.wikimedia.org/w/index.php' __dir__ = os.path.dirname(__file__) try: with open(os.path.join(__dir__, 'config.yaml')) as config_file: app.config.update(yaml.safe_load(config_file)) except FileNotFoundError: print('config.yaml file not found, assuming local development setup') app.secret_key = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(64)) if 'oauth' in app.config: consumer_token = mwoauth.ConsumerToken(app.config['oauth']['consumer_key'], app.config['oauth']['consumer_secret']) @app.template_global()
import mwapi{% if cookiecutter.set_up_mypy == "True" %} # type: ignore{% endif %} import mwoauth{% if cookiecutter.set_up_mypy == "True" %} # type: ignore{% endif %} import os import random import requests_oauthlib{% if cookiecutter.set_up_mypy == "True" %} # type: ignore{% endif %} import string import toolforge {% if cookiecutter.set_up_mypy == "True" %}from typing import Optional, Tuple, Union import werkzeug {% endif %}import yaml app = flask.Flask(__name__) user_agent = toolforge.set_user_agent( '{{ cookiecutter.tool_identifier }}', email='{{ cookiecutter.user_email }}') __dir__ = os.path.dirname(__file__) try: with open(os.path.join(__dir__, 'config.yaml')) as config_file: app.config.update(yaml.safe_load(config_file)) except FileNotFoundError: print('config.yaml file not found, assuming local development setup') characters = string.ascii_letters + string.digits random_string = ''.join(random.choice(characters) for _ in range(64)) app.secret_key = random_string if 'oauth' in app.config: oauth_config = app.config['oauth'] consumer_token = mwoauth.ConsumerToken(oauth_config['consumer_key'],
#!/usr/bin/env python3 import time import mwapi # type: ignore import toolforge user_agent = toolforge.set_user_agent('lexeme-forms', email='*****@*****.**') session = mwapi.Session(host='https://www.wikidata.org', user_agent=user_agent) for result in session.post( action='purge', generator='allpages', gapnamespace=146, # Lexeme gaplimit=30, # rate limit permits 30 purges per 60 seconds forcelinkupdate=True, continuation=True): pages = result['purge'] first_id = pages[0]['title'][len('Lexeme:'):] last_id = pages[-1]['title'][len('Lexeme:'):] print('Purged {:>6} ... {:>6}'.format(first_id, last_id), flush=True) time.sleep( 75 ) # rate limit permits 30 purges per 60 seconds, +15s for some buffer print('Done.')
#!/usr/bin/env python3 # GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 # Copyright (c) 2020 QEDK # A copy of the license is available at https://raw.githubusercontent.com/QEDK/qedkbot/master/LICENSE import pywikibot from pywikibot import Page import toolforge import requests import re toolforge.set_user_agent('qedkbot') site = pywikibot.Site() site.login() checkpage = Page(site, "User:QEDKbot/Task 1 disable") statuspage = Page(site, "User:QEDKbot/Task 1 status") def emergency(): if (checkpage.text != "true"): statuspage.text = "off" statuspage.save(summary="Task 1: tagging disabled.") print("Shutoff") exit(0) else: statuspage.text = "on" statuspage.save(summary="Task 1: tagging enabled.") emergency()
import random import requests import requests_oauthlib import string import toolforge import yaml import ids import scripts import unicodescripts app = flask.Flask(__name__) app.before_request(toolforge.redirect_to_https) toolforge.set_user_agent('speedpatrolling', email='*****@*****.**') user_agent = requests.utils.default_user_agent() __dir__ = os.path.dirname(__file__) try: with open(os.path.join(__dir__, 'config.yaml')) as config_file: app.config.update(yaml.safe_load(config_file)) except FileNotFoundError: print('config.yaml file not found, assuming local development setup') app.secret_key = ''.join( random.choice(string.ascii_letters + string.digits) for _ in range(64)) if 'oauth' in app.config: consumer_token = mwoauth.ConsumerToken( app.config['oauth']['consumer_key'], app.config['oauth']['consumer_secret'])
import requests_oauthlib # type: ignore import string import toolforge import werkzeug import yaml from SPARQLWrapper import SPARQLWrapper, JSON from typing import Optional APIURL = "https://www.wikidata.org/w/api.php" QUERIES = "queries" MAPPINGS = "mappings" HASHTAG = "#Hauki" LABELLANG = "en" LABELCACHE = {} user_agent = toolforge.set_user_agent('hauki', email='*****@*****.**') sparql = SPARQLWrapper("https://query.wikidata.org/sparql", agent=user_agent) app = flask.Flask(__name__) __dir__ = os.path.dirname(__file__) try: with open(os.path.join(__dir__, 'config.yaml')) as config_file: app.config.update(yaml.safe_load(config_file)) except FileNotFoundError: print('config.yaml file not found, assuming local development setup') characters = string.ascii_letters + string.digits random_string = ''.join(random.choice(characters) for _ in range(64)) app.secret_key = random_string
import acnutils as utils from string import Template from dataclasses import dataclass from datetime import datetime from typing import Optional, Tuple, Iterator, Iterable, cast, Dict, Union __version__ = "1.0" logger = utils.getInitLogger("essayassesment", level="VERBOSE", filename="essayimpact.log") site = pywikibot.Site("en", "wikipedia") session = requests.session() session.headers.update( {"User-Agent": toolforge.set_user_agent("anticompositebot")}) simulate = False @dataclass class Essay: page: pywikibot.Page links: Optional[int] = None watchers: Optional[int] = None views: Optional[int] = None score: Optional[float] = None def get_views_and_watchers(self) -> None: title = self.page.title() url = "https://en.wikipedia.org/w/api.php" params = {
import re import json import sqlite3 import toolforge from enums import CSDCATS, RMCATCMT, ADDCATCMT from sseclient import SSEClient as EventSource from phpserialize import unserialize toolforge.set_user_agent( 'GlobalCSD/0.1 (https://tools.wmflabs.org/globalcsd/; https://meta.wikimedia.org/wiki/User_talk:WhitePhosphorus) Python/3.5 update.py/0.1' ) conn = sqlite3.connect('pages.db') cur = conn.cursor() # get title from the summaries like "[[:title]] removed from category" add_title_re = re.compile(r'|'.join( [s.replace('[[:$1]]', r'\[\[:(.+)\]\]') for s in ADDCATCMT.values()])) rm_title_re = re.compile(r'|'.join( [s.replace('[[:$1]]', r'\[\[:(.+)\]\]') for s in RMCATCMT.values()])) # load admin list to memory cur.execute('''SELECT site, GROUP_CONCAT(username, '|') FROM admin GROUP BY site''') all_admins = {wiki: users.split('|') for (wiki, users) in cur.fetchall()} def tools_conn(): # a cache of connections to toolforge databases _toolforge_conns = dict()
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ import datetime import json import os import phabricator import requests import toolforge import wikimediaci_utils as ci toolforge.set_user_agent('extreg-wos') with open('config.json') as f: conf = json.load(f) ON_LABS = os.environ.get('INSTANCEPROJECT') == 'tools' phab = phabricator.Phabricator(conf['PHAB_HOST'], conf['PHAB_USER'], conf['PHAB_CERT']) s = requests.Session() MW_DIR = '/data/project/extreg-wos/src' if ON_LABS else '/home/km/gerrit/mediawiki/core' WMF_TRACKING = 87875 OTHER_TRACKING = 98668 OUTPUT_DIR = '/data/project/extreg-wos/public_html/' if ON_LABS else '' PATCH_TO_REVIEW = 'PHID-PROJ-onnxucoedheq3jevknyr' EASY = 'PHID-PROJ-2iftynis5nwxv3rpizpe'