<jupyter_start><jupyter_text>This is a demonstration of how to use requests in Python. In this example, we are using requests to access a file using the GitHub API. The resulting JSON object contains a base64-encoded attribute (content), which is decoded, tuned into a list of lines. Lastly, we select some lines of interest.This example is used in our work on software metrics and the literal include service (for writing projects).<jupyter_code>import requests
import base64
r = requests.get("https://api.github.com/repos/gkthiruvathukal/st-hec/contents/hydra/dataserver.py")
print(r.status_code)


r.json().keys()
b64data = r.json().get('content')

lines = base64.b64decode(b64data).decode("utf-8").split('\n')
selected_lines = lines[10:30]
print("\n".join(selected_lines))<jupyter_output>#   (at your option) any later version.
#
#   The Hydra Filesystem is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with the Hydra Filesystem; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
#######################################################################################



from common import network_services,packet_builder,packet_types,synchronized
from common.dispatch import Dispatcher
from common.rep_db import *
from common import plugin<jupyter_text>This shows how to base64 encode text. b64encode() expects bytes and returns bytes (b).<jupyter_code>text = "How to encode some text"
bytes = text.encode("UTF-8")
encoded = base64.b64encode(bytes)
encoded<jupyter_output><empty_output><jupyter_text>To get the string representation of bytes, use decode().<jupyter_code>encoded.decode("UTF-8")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12901580826109127, 'fraction_numerical': 0.019377868434472208, 'mean_word_length': 5.583892617449664, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '567580', 'license': 'MIT', 'n_tokens_mistral': 585, 'n_tokens_neox': 551, 'n_words': 208, 'path': 'examples/requests.ipynb', 'repo_name': 'gkthiruvathukal/notebooks', 'size': '1961'}