copy editor hunter

raw

README.rst

Script to fix typos in stackoverflow question titles.

I used it to get the golden "Copy Editor" badge by automatically editing 200+ questions.

raw

copyeditor-earned.png

copyeditor-earned.png
raw

fix.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
// https://stackexchange.com/oauth/dialog?client_id=9796&scope=write_access&redirect_uri=https://stackexchange.com/oauth/login_success
$key = 'FIXME';
$access_token = 'FIXME';
$apiUrl = 'https://api.stackexchange.com/2.2/';
$site = 'stackoverflow';
 
require_once 'HTTP/Request2.php';
 
//search
// https://api.stackexchange.com/docs/search
$req = new HTTP_Request2(
    $apiUrl . 'search?' . http_build_query(
        [
            'key'          => $key,
            'access_token' => $access_token,
            'order'        => 'desc',
            'sort'         => 'activity',
            // https://api.stackexchange.com/docs/filters
            // filter must be "unsafe"!
            //'filter'       => 'withbody',
            'filter'       => ')peeUKlrI1gEM_K5k96Qk8IC',
            'site'         => $site,
            'intitle'      => 'javasript',//fix 1
            'intitle'      => 'javascipt',//fix 2
        ]
    )
);
$res = $req->send();
 
$data = json_decode($res->getBody());
 
foreach ($data->items as $question) {
    echo $question->question_id . "\n";
    echo ' ' . $question->link . "\n";
 
    if (file_exists(__DIR__ . '/fixed/' . $question->question_id)) {
        echo " already fixed\n";
        continue;
    }
 
    echo ' title: ' . $question->title . "\n";
    $fixed = str_replace(
        // fix 1: JavaSript
        //['javasript', 'Javasript', 'JavaSript', 'javaSript'],
        // fix 2: JavaScipt
        ['javascipt', 'Javascipt', 'JavaScipt', 'JavaScipt'],
        ['javascript', 'JavaScript', 'JavaScript', 'JavaScript'],
        $question->title
    );
    echo ' fixed: ' . $fixed . "\n";
 
    if ($fixed == $question->title) {
        echo " !! title did not change, skipping\n";
        continue;
    }
    //var_dump($question);die();
 
    // https://api.stackexchange.com/docs/edit-question
    // filter can be created there
    $wreq = new HTTP_Request2(
        $apiUrl . 'questions/' . $question->question_id . '/edit',
        'POST'
    );
    $wreq->addPostParameter('key', $key);
    $wreq->addPostParameter('access_token', $access_token);
    $wreq->addPostParameter('site', $site);
    $wreq->addPostParameter('title', $fixed);
    $wreq->addPostParameter('body', $question->body_markdown);
    $wreq->addPostParameter('tags', implode(',', $question->tags));
    $res = $wreq->send();
    if ($res->getStatus() == 200) {
        //mark fixed
        echo " fixed!\n";
        file_put_contents(
            __DIR__ . '/fixed/' . $question->question_id, ''
        );
        //echo $res->getBody() . "\n";//die();
        sleep(4);
        //exit(0);
    } else {
        echo "ERROR\n";
        echo $res->getBody() . "\n";
        exit(1);
    }
}
?>
 
raw

fixes.png

fixes.png
Christian Weiske Christian Weiske
owner

History