<s> import re <EOL> import json <EOL> from bs4 import BeautifulSoup <EOL> import requests <EOL> RESOURCES = { } <EOL> BASE_URL = "<STR_LIT>" <EOL> _HEADERS = { '<STR_LIT>' : '<STR_LIT>' } <EOL> with open ( '<STR_LIT>' , '<STR_LIT:r>' ) as f : <EOL> RESOURCES = json . loads ( f . read ( ) ) <EOL> def get_summary ( content ) : <EOL> """<STR_LIT>""" <EOL> soup = BeautifulSoup ( content , "<STR_LIT>" ) <EOL> summary = soup . find_all ( attrs = { <EOL> '<STR_LIT:class>' : re . compile ( r"<STR_LIT>" ) } ) <EOL> if summary [ <NUM_LIT:0> ] . p . string is None : <EOL> return summary [ <NUM_LIT:0> ] . p . p . getText ( ) <EOL> return summary [ <NUM_LIT:0> ] . p . getText ( ) <EOL> def get_rules ( license ) : <EOL> """<STR_LIT>""" <EOL> can = [ ] <EOL> cannot = [ ] <EOL> must = [ ] <EOL> req = requests . get ( "<STR_LIT>" . format ( <EOL> base_url = BASE_URL , license = license ) , headers = _HEADERS ) <EOL> if req . status_code == requests . codes . ok : <EOL> data = req . json ( ) <EOL> can = data [ "<STR_LIT>" ] <EOL> cannot = data [ "<STR_LIT>" ] <EOL> must = data [ "<STR_LIT>" ] <EOL> return can , cannot , must <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> all_summary = { } <EOL> for license in RESOURCES : <EOL> req = requests . get ( RESOURCES [ license ] ) <EOL> if req . status_code == requests . codes . ok : <EOL> summary = get_summary ( req . text ) <EOL> can , cannot , must = get_rules ( license ) <EOL> all_summary [ license ] = { <EOL> "<STR_LIT>" : summary , <EOL> "<STR_LIT:source>" : RESOURCES [ license ] , <EOL> "<STR_LIT>" : can , <EOL> "<STR_LIT>" : cannot , <EOL> "<STR_LIT>" : must <EOL> } <EOL> with open ( '<STR_LIT>' , '<STR_LIT>' ) as f : <EOL> f . write ( json . dumps ( all_summary , indent = <NUM_LIT:4> ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
