Skip to content

dashes in username causes problems with search #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 26 additions & 26 deletions credditbot.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

// creddit.php
// credditbot.php

class Creddit
{
Expand All @@ -17,7 +17,7 @@ public function statistics($username)
$user_info['total_karma'] = $user_info['link_karma'] + $user_info['comment_karma'];
$user_info['total_karma_human'] = number_format($user_info['link_karma'] + $user_info['comment_karma']);

$bad_karma = json_decode($this->curl("http://www.reddit.com/r/badkarma/search.json?q=title%3A$username&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
$bad_karma = json_decode($this->curl("http://www.reddit.com/r/badkarma/search.json?q=title%3A%27$username%27&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
if(count($bad_karma['data']['children']) > 0)
$user_info['bad_karma'] = true;

Expand All @@ -38,7 +38,7 @@ public function statistics($username)
'requested' => $loan_tags['req'] + $loan_tags['request'],
);

$report_search = json_decode($this->curl("http://www.reddit.com/r/Loans/search.json?q=title%3A$username+%5BPAID%5D+OR+%5BUNPAID%5D&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
$report_search = json_decode($this->curl("http://www.reddit.com/r/Loans/search.json?q=title%3A%27$username%27+%5BPAID%5D+OR+%5BUNPAID%5D&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
$report_tags = array('unpaid' => 0, 'paid' => 0);

foreach($report_search['data']['children'] as $submission) {
Expand Down Expand Up @@ -105,19 +105,19 @@ class Reddit
{
function login($username, $password)
{
$login_url = "https://ssl.reddit.com/api/login/cRedditBot";
$login_data = array (
$login_url = "https://ssl.reddit.com/api/login/cRedditBot";
$login_data = array (
"user" => $username,
"passwd" => $password,
"api_type" => "json",
);
);

$ch = curl_init ($login_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "r/Loans cRedditBot Bot by u/interwhos");
$login_response = curl_exec($ch);
$ch = curl_init ($login_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $login_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "r/Loans cRedditBot Bot by u/interwhos");
$login_response = curl_exec($ch);

$account_data = json_decode($login_response, true);
$account_data = $account_data['json']['data'];
Expand All @@ -138,20 +138,20 @@ function get_post($id)

function post_comment($id, $body)
{
$comment_url = "https://ssl.reddit.com/api/comment";
$comment_data = array(
$comment_url = "https://ssl.reddit.com/api/comment";
$comment_data = array(
"thing_id" => 't3_' . $id,
"text" => $body,
"uh" => $this->modhash,
);

$ch = curl_init($comment_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $comment_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "r/Loans cRedditBot Bot by u/interwhos");
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie);
$return_data = curl_exec($ch);
);

$ch = curl_init($comment_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $comment_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "r/Loans cRedditBot Bot by u/interwhos");
curl_setopt($ch, CURLOPT_COOKIE, $this->cookie);
$return_data = curl_exec($ch);
return $return_data;
}

Expand Down Expand Up @@ -213,8 +213,8 @@ private function curl($url)
---------------------------------------\n\n
**Requester Stats**\n\n
* [{$loan_info['requested']} Loan(s) Requested](/req_) ([view all posts in r/loans by this user](http://www.reddit.com/r/Loans/search?syntax=cloudsearch&q=author%3A%27$username%27&restrict_sr=on&sort=new))
* [{$loan_info['requested_paid']} Loan(s) Paid Back By This Redditor](/paid_) ([view](http://www.reddit.com/r/Loans/search?q=title%3A$username+%5BPAID%5D&restrict_sr=on&sort=new))
* [{$loan_info['requested_unpaid']} Loan(s) NOT Paid Back By This Redditor](/unpaid_) ([view](http://www.reddit.com/r/Loans/search?q=title%3A$username+%5BUNPAID%5D&restrict_sr=on&sort=new))\n\n
* [{$loan_info['requested_paid']} Loan(s) Paid Back By This Redditor](/paid_) ([view](http://www.reddit.com/r/Loans/search?q=title%3A%27$username%27+%5BPAID%5D&restrict_sr=on&sort=new))
* [{$loan_info['requested_unpaid']} Loan(s) NOT Paid Back By This Redditor](/unpaid_) ([view](http://www.reddit.com/r/Loans/search?q=title%3A%27$username%27+%5BUNPAID%5D&restrict_sr=on&sort=new))\n\n
**Lender Stats**\n\n
* [{$loan_info['granted']} Loan(s) Granted To Others](/offer_)
* [{$loan_info['granted_paid']} Loan(s) Paid Back To This Redditor](/paid_)
Expand All @@ -234,4 +234,4 @@ private function curl($url)

sleep(600); // TODO: Look at the captcha problem; this COULD cause a comment overlap!
}
?>
?>
18 changes: 9 additions & 9 deletions credditrating.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function statistics($username)
$user_info['total_karma'] = $user_info['link_karma'] + $user_info['comment_karma'];
$user_info['total_karma_human'] = number_format($user_info['link_karma'] + $user_info['comment_karma']);

$bad_karma = json_decode($this->curl("http://www.reddit.com/r/badkarma/search.json?q=title%3A$username&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
$bad_karma = json_decode($this->curl("http://www.reddit.com/r/badkarma/search.json?q=title%3A%27$username%27&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
if(count($bad_karma['data']['children']) > 0)
$user_info['bad_karma'] = true;

Expand All @@ -38,7 +38,7 @@ public function statistics($username)
'requested' => $loan_tags['req'] + $loan_tags['request'],
);

$report_search = json_decode($this->curl("http://www.reddit.com/r/Loans/search.json?q=title%3A$username+%5BPAID%5D+OR+%5BUNPAID%5D&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
$report_search = json_decode($this->curl("http://www.reddit.com/r/Loans/search.json?q=title%3A%27$username%27+%5BPAID%5D+OR+%5BUNPAID%5D&restrict_sr=on&sort=relevance&t=all&limit=500"), true);
$report_tags = array('unpaid' => 0, 'paid' => 0);

foreach($report_search['data']['children'] as $submission) {
Expand Down Expand Up @@ -171,18 +171,18 @@ private function time_ago($datetime, $granularity = 2)
<?php if($loan_info['requested'] > 0) { ?>
<ul>
<li>
<a href="http://www.reddit.com/r/Loans/search?q=author:<?php echo $user_info['name']; ?>+title:req+OR+title:request&restrict_sr=on&sort=new&t=all">
<a href="http://www.reddit.com/r/Loans/search?q=author:%27<?php echo $user_info['name']; ?>%27+title:req+OR+title:request&restrict_sr=on&sort=new&t=all">
<?php echo $loan_info['requested']; ?>
</a>
loans requested
</li>
<li>
<a href="http://www.reddit.com/r/Loans/search?q=title:<?php echo $user_info['name']; ?>+PAID&restrict_sr=on&sort=new&t=all">
<a href="http://www.reddit.com/r/Loans/search?q=title:%27<?php echo $user_info['name']; ?>%27+PAID&restrict_sr=on&sort=new&t=all">
<?php echo $loan_info['requested_paid']; ?>
</a>
loans paid back</li>
<li>
<a href="http://www.reddit.com/r/Loans/search?q=title:<?php echo $user_info['name']; ?>+UNPAID&restrict_sr=on&sort=new&t=all">
<a href="http://www.reddit.com/r/Loans/search?q=title:%27<?php echo $user_info['name']; ?>%27+UNPAID&restrict_sr=on&sort=new&t=all">
<?php echo $loan_info['requested_unpaid']; ?>
</a>
loans <strong>not</strong> paid back :(</li>
Expand All @@ -195,19 +195,19 @@ private function time_ago($datetime, $granularity = 2)
<?php if($loan_info['granted'] > 0) { ?>
<ul>
<li>
<a href="http://www.reddit.com/r/Loans/search?q=author:<?php echo $user_info['name']; ?>+title:PAID+OR+UNPAID&restrict_sr=on&sort=new&t=all">
<a href="http://www.reddit.com/r/Loans/search?q=author:%27<?php echo $user_info['name']; ?>%27+title:PAID+OR+UNPAID&restrict_sr=on&sort=new&t=all">
<?php echo $loan_info['granted']; ?>
</a>
loans granted to others</li>
</li>
<li>
<a href="http://www.reddit.com/r/Loans/search?q=author:<?php echo $user_info['name']; ?>+title:PAID&restrict_sr=on&sort=new&t=all">
<a href="http://www.reddit.com/r/Loans/search?q=author:%27<?php echo $user_info['name']; ?>%27+title:PAID&restrict_sr=on&sort=new&t=all">
<?php echo $loan_info['granted_paid']; ?>
</a>
loans repaid by others</li>
</li>
<li>
<a href="http://www.reddit.com/r/Loans/search?q=author:<?php echo $user_info['name']; ?>+title:UNPAID&restrict_sr=on&sort=new&t=all">
<a href="http://www.reddit.com/r/Loans/search?q=author:%27<?php echo $user_info['name']; ?>%27+title:UNPAID&restrict_sr=on&sort=new&t=all">
<?php echo $loan_info['granted_unpaid']; ?>
</a>
loans <strong>not</strong> repaid by others :(</li>
Expand All @@ -219,4 +219,4 @@ private function time_ago($datetime, $granularity = 2)
</div>
<?php } ?>
</body>
</html>
</html>