Skip to content

Instantly share code, notes, and snippets.

@ulasozguler
Last active October 7, 2017 10:05
Show Gist options
  • Save ulasozguler/3a1bdb95403a6f1ce5ee71476afd09a5 to your computer and use it in GitHub Desktop.
Save ulasozguler/3a1bdb95403a6f1ce5ee71476afd09a5 to your computer and use it in GitHub Desktop.
A better list of subscribed Facebook bugs
import json
import requests
headers = {
'pragma': 'no-cache',
'origin': 'https://developers.facebook.com',
'accept-language': 'en-GB,en;q=0.8,en-US;q=0.6,tr;q=0.4',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'content-type': 'application/x-www-form-urlencoded',
'accept': '*/*',
'cache-control': 'no-cache',
'authority': 'developers.facebook.com',
'cookie': '-- YOUR developers.facebook.com COOKIES SHOULD BE HERE --',
'referer': 'https://developers.facebook.com/bugs/subscribed/',
}
params = (
('search', 'subscribed'),
('size', '1000'),
('value', ''), # search
('tag_ids', ''), # tags
('dpr', '2'),
)
data = [
('__user', '-- YOUR FB ACCOUNT ID HERE --'),
('fb_dtsg', '-- THIS RARELY CHANGES BUT NEEDS TO BE TAKEN FROM POST REQUEST ON FACEBOOK BUGS PAGE --'),
('__a', '1'),
]
response = requests.post('https://developers.facebook.com/bugs/search_source/',
headers=headers, params=params, data=data)
result = json.loads(response.text.replace('for (;;);', ''))['payload']['entries']
def status(bug_status):
if bug_status in ['Assigned', 'Duplicate']:
color = '#CDCD00'
elif bug_status in ['Fixed', 'Fix Ready']:
color = 'green'
elif bug_status in ['Need More Info']:
color = '#6B4AFF'
elif bug_status in ['Won\'t Fix', 'Closed', 'By Design', 'Invalid']:
color = 'red'
else:
color = 'black'
return '<span class="color color-{color}" style="color: {color}">{status_name}</span>'.format(color=color,
status_name=bug_status)
def format_date(date_str):
date_month = date_str.split(' ')[0]
return date_str.replace(date_month, date_month[0:3])
header = """
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.9/css/jquery.dataTables.min.css">
<style>
* { font-family: Arial, Helvetica, sans-serif; font-size: 12px; }
table.dataTable tbody tr:nth-child(odd) { background-color: #F0F0F0; !important; }
td, th { padding: 10px !important; }
#failRate { float: left; padding: 5px; color: red; font-weight: bold; }
thead tr { background-color: #DBDBDB; }
#datatable_filter { margin-bottom: 10px; }
</style>
<script type="text/javascript" language="javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.9/js/jquery.dataTables.min.js"></script>
"""
footer = """
<script>
$(document).ready(function() {
$('#datatable').DataTable({
"paging": false,
"order": [],
"drawCallback": function( settings ) {
var total = $('.color').length;
if(total === 0) {
var failRate = 'N/A';
} else {
var fail = $('.color-red').length;
var failRate = (fail / total * 100).toFixed(2) + '%';
}
var failRateText = 'Closed / Total: ' + failRate;
if($('#failRate').length === 0) {
$('<div id="failRate">' + failRateText + '</div>').insertBefore($("#datatable_filter"));
} else {
$('#failRate').html(failRateText);
}
}
});
});
</script>
"""
body = """
<table id="datatable" class="dataTable">
<thead>
<tr>
<th style="width: 400px">Bug</th>
<th>Creator</th>
<th style="width: 110px">Updated</th>
<th>Subs.</th>
<th>Status</th>
</tr>
</thead>
<tbody>
{rows_html}
</tbody>
</table>
"""
row_template = """<tr>
<td><a href="{url}" target="_blank">{text}</a></td>
<td>{creator_name}</td>
<td>{date_formatted}</td>
<td>{subscriber_count}</td>
<td>{status_name}</td>
</tr>
"""
rows_html = ''
for row in result:
row['url'] = 'https://developers.facebook.com%s' % row['uri']
row['date_formatted'] = format_date(row['last_update_time_friendly'])
row['status_name'] = status(row['status_name'])
rows_html += row_template.format(**{k: v.encode('utf-8') if isinstance(v, basestring) else v
for k, v in row.iteritems()})
html = header + body.format(rows_html=rows_html) + footer
with open('bugs_generated.htm', 'w') as f:
f.write(html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment