Exemple #1
0
from json import loads as l
from requests import get as g
from pandas.io.json import json_normalize as n
from bs4 import BeautifulSoup as b
from pandas import concat as c

c([
    n(
        l(
            g("https://xkcd.com<id>info.0.json".replace("<id>",
                                                        link["href"])).text))
    for link in b(g("https://xkcd.com/archive/").text).find(
        id="middleContainer").find_all("a")
]).to_pickle("xkcd_metadata.pkl")
Exemple #2
0
import motor.motor_asyncio as amotor
from json import loads as l
import asyncio
url = l(open("configs.json").read())['data']['url']


class GuildDB:
    def __init__(self):
        self.client = amotor.AsyncIOMotorClient(url)
        self.db = self.client['Guildstore']
        self.collections = []
        self.collection = ""

    async def add_collection(self, name: str):
        self.collections += [name]
        self.collections = list(set(self.collections))
        self.collection = name
        if name not in (await self.db.list_collection_names()):
            await self.db.create_collection(name=name)

    async def remove_collection(self, name: str):
        self.collections.remove(name)
        await self.db.drop_collection(name)

    def set_collection(self, name: str):
        self.collection = name

    async def insert(self, **kwargs):
        await self.db[self.collection].insert_one(kwargs)

    async def insert_many(self, *items):
Exemple #3
0
import time
from urllib.request import urlopen as u
from urllib.parse import unquote as uqu
from sys import argv
from json import loads as l
import os
import random


def dlistdir(q):
    return [w for w in os.listdir(q) if w != '...']


os.chdir('/'.join(argv[0].split('/')[:-1]))
os.system('rm hexit')
a = l(open('0/...').read())
for w in list(a.keys()):
    if a[w] != os.path.getsize(w):
        del (a[w])
        os.remove(w)
        print(w)
open('0/...', 'w').write(str(a).replace("'", '"'))

q = [w.split() for w in os.popen('ifconfig').read().split('\n')]
q = [w[1] for w in q if len(w) and w[0] == 'inet']
q = [w[([int(ww in '1234567890') for ww in w] + [1]).index(1):] for w in q]
q = [
    w[:([int(ww not in '1234567890.') for ww in w] + [1]).index(1)] for w in q
]
#q=[w[1].split(':')[1] for w in q if len(w) and w[0] == 'inet']
print('=' * 10, *enumerate(q), sep='\n')
Exemple #4
0
from json import loads as l
print((lambda mylocation : l(open('data-2897-2019-01-10.json').read())[min(range(len(l(open('data-2897-2019-01-10.json').read()))), key=[((mylocation[0]-distance[0])**2+(mylocation[1]-distance[1])**2) for distance in [dct['geoData']['coordinates'] for dct in l(open('data-2897-2019-01-10.json').read())]].__getitem__)])([float(input('Введите долготу')), float(input('Введите широту'))]))
Exemple #5
0
def load(fp):
    with open(fp, 'r') as f:
        res = l(f)
    return res
from pykakasi import kakasi as ka
from json import loads as l, dumps as d

with open('ja_jp.json', 'r') as f:
	srt=f.read()

j=l(srt)
k=ka()
k.setMode('J','aF')
# conv=k.getConverter()

# for key in j:
# 	j[key] = conv.do(j[key])

k.setMode('K','aF')
conv=k.getConverter()

for key in j:
	j[key] = conv.do(j[key]).replace('aa','ā').replace('ou','ō').replace('oo','ō').replace('nippon','nihon').replace('ii','ī').replace('uu','ū')

with open('ja_rj.json', 'w') as f:
	f.write(d(j, indent=4))
Exemple #7
0
 def do_GET(self):
  if os.path.exists('exit'):
   raise KeyboardInterrupt
  global admin
  self.send_response(200)
  path='.'+uqu(self.path)
  if path =='./0/0/' and admin==1:
   self.send_header("Content-type", "text/html; charset=utf-8")
   self.end_headers()
   self.wfile.write(bytes('''
   <html>
   <head>
   <title>'''+path+'''</title>
   </head>
   <style type=text/css>
    #neko {position: fixed; top:0; botom:0; left:0; right:0}
    #main {position: absolute; top:0; left:0}
    wi {background: #00ff00}
    </style>
   <body>
   <div id="neko">
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"></div>

   <div id="main">
   <h1><wi>Enter password</wi></h1>

   <wi><form method="post">
   <textarea name="a"></textarea><br>
   <input type="submit" value="enter"></form></wi>
   <wi>===</wi>

   <form><button formaction="../">
   <h1>..<img src="/favicon.ico" height="25"></h1>
   </button></form>
   <wi>===</wi>

   </div></body></html>''', "utf-8"))
   return None

  if '?' in path:
   self.send_header("Content-type", "text/html; charset=utf-8")
   self.end_headers()
   self.wfile.write(bytes('''
   <html>
   <head>
   <meta http-equiv="refresh" content="0;URL=.">
   </meta>
   </head>
   <body>
   <style type=text/css>
    #neko {position: fixed; top:0; botom:0; left:0; right:0}
    #main {position: absolute; top:0; left:0}
    wi {background: #00ff00}
    </style>
   <div id="neko">
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"></div>
   </body>
   </html>''', "utf-8"))

  elif path in ['./','.']:
   self.send_header("Content-type", "text/html; charset=utf-8")
   self.end_headers()
   self.wfile.write(bytes('''
   <html>
   <head>
   <meta http-equiv="refresh" content="1;URL=0/">
   </meta>
   </head>
   <body>
   <style type=text/css>
    #neko {position: fixed; top:0; botom:0; left:0; right:0}
    #main {position: absolute; top:0; left:0}
    wi {background: #00ff00}
    </style>
   <div id="neko">
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"></div>
   </body>
   </html>''', "utf-8"))

  elif os.path.isdir(path):
   if img == '/nekopara.jpg':
    os.system('pwd')
    os.system('cp nekopara/'+random.choice(os.listdir('./nekopara'))+' nekopara.jpg')
   a=open('clip')
   clip=a.read()
   a.close()
   self.send_header("Content-type", "text/html; charset=utf-8")
   self.end_headers()
   self.wfile.write(bytes('''
   <html>
   <head>
   <title>'''+path+'''</title>
   </head>
   <style type=text/css>
    #neko {position: fixed; top:0; botom:0; left:0; right:0}
    #main {position: absolute; top:0; left:0}
    wi {background: #00ff00}
    </style>
   <body>
   <div id="neko">
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"></div>

   <div id="main">
     ''','utf-8'))
   if path == './0/':
    self.wfile.write(bytes('''
    <h1>
     <form enctype="multipart/form-data" method="post" name="sendfile">
      <wi>
       <input type="file" name="u">
       <inp id="inp">
        <input type="submit">
       </inp>
      </wi>
     </form>
    </h1>
    <div id="log"></div>
    <wi>===</wi>

   <script>
    document.forms.sendfile.onchange=function(){
     var file=this.elements.u.files[0]
     if (file) {
      document.getElementById('maincont').innerHTML=''
      document.getElementById('inp').innerHTML=''
      x=new XMLHttpRequest();
      x.upload.onprogress=function(){
       if (event.loaded!=event.total){
        document.getElementById('log') .innerHTML='<wi>'+event.loaded+'<br/>'+event.total+'</wi>'
        }
       else{
        location.reload(true)
       }
      }
      x.open("POST",'.')
      var a=file.name
      var e=''
      var w=0
      for (w=0;w<a.length;w+=1){
       e+=a.charCodeAt(w).toString()+'a'
      }
      x.setRequestHeader("fn",e)
      x.send(file)
     }
    }
   </script>

     ''','utf-8'))
   self.wfile.write(bytes('''
   <maincont id="maincont">

     ''','utf-8'))
   if path == './0/':
    self.wfile.write(bytes('''

   <wi><form method="post">
   <textarea name="c">'''+clip+'''</textarea><br>
   <input type="submit" value="save"></form></wi>
   <wi>===</wi>

   ''','utf-8'))
   self.wfile.write(bytes('''
   <form><button formaction="../">
   <h1>..<img src="/favicon.ico" height="25"></h1>
   </button></form>
   <wi>===</wi>
   ''','utf-8'))
   if admin==2:
    self.wfile.write(bytes('''
   <form method="post"><button formaction="/0/" name="e" value="1">
   <h1>exit</h1>
   </button></form>
   <wi>===</wi>
   ''','utf-8'))

   ld=list(dlistdir(path))
   ld=ld[::-1]
   for w in ld:
    self.wfile.write(bytes('''
    <form><button formaction="'''+w+'''/">
    <h1>'''+w+'''
    <img src="/favicon.ico" height="25">'''*int(os.path.isdir(path+w))+'''
    </h1></button></form>''','utf-8'))

   self.wfile.write(bytes('''</maincont></div></body></html>''', "utf-8"))

  elif os.path.isfile(path):
   if ngrok or path[:4]!='./0/':
    q=open(path,'br')
    di=l(open('0/...').read())
    if path in di.keys():
     tosend=l(open('0/...').read())[path]
     toread=0
     self.send_header("Content-type", "file/file")
     self.send_header("Content-Length", str(tosend))
     self.end_headers()
     while toread<tosend:
      read=q.read()
      self.wfile.write(read)
      toread+=len(read)
    else:
     self.send_header("Content-type", "file/file")
     self.send_header("Content-Length", str(os.path.getsize(path)))
     self.end_headers()
     self.wfile.write(q.read())
    if ngrok == 2:
     raise KeyboardInterrupt
   else:
    self.send_response(200)
    global hostName
    global hostPort
    global exex
    port=exex()
    self.send_header("Content-type", "text/html; charset=utf-8")
    self.end_headers()
    self.wfile.write(bytes('''
   <html><head><title>'''+path+'''</title>
   <meta http-equiv="refresh" content="1;URL=http://'''+hostName+':'+port+path[1:]+'''"></meta>
   </head>
   <body>
   <style type=text/css>
    #neko {position: fixed; top:0; botom:0; left:0; right:0}
    #main {position: absolute; top:0; left:0}
    wi {background: #00ff00}
    </style>
   <div id="neko">
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"></div>
   <div id="main">
   <h1>
   <form><button formaction="./">..<img src="/favicon.ico" height="25"></button>
   </form>
   </h1>
   </div></body></html>
   ''', "utf-8"))
  elif os.path.isfile(path[:-1]) and path[-1] == '/':
   self.send_header("Content-type", "text/html; charset=utf-8")
   self.end_headers()
   self.wfile.write(bytes('''
   <html><head><title>'''+path+'''</title>
   </head>
   <body>
   <style type=text/css>
    #neko {position: fixed; top:0; botom:0; left:0; right:0}
    #main {position: absolute; top:0; left:0}
    wi {background: #00ff00}
    </style>
   <div id="neko">
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"></div>
   <div id="main">
   <h1>
   <form><button formaction="../">..<img src="/favicon.ico" height="25"></button>
   </form>
   <wi><br>'''+path[1:-1]+'<br>size:'+str(os.path.getsize(path[:-1]))+'''</wi><br>
   </h1>
   <a href="'''+path[1:-1]+'''"><img src='/download.png' width=100%></a><br>
   </div></body></html>
   ''', "utf-8"))
  else:
   self.send_header("Content-type", "text/html; charset=utf-8")
   self.end_headers()
   self.wfile.write(bytes("<html><head><title>"+path+"</title></head>", "utf-8"))
   self.wfile.write(bytes('<body><p>not found<br>'+path[1:]+'</p></body></html>', "utf-8"))
Exemple #8
0
 def do_POST(self):
  global admin
  lenn=int(self.headers['Content-Length'])
  ct=self.headers['Content-Type']
  ct=str(ct).split('/')
  o=ct[1:]
  ct=ct[0]

  print(self.headers)
  if ct=='multipart':
   blen=len(o[0].split('=')[1])+8
   if 1:
    data=bytearray()
    while data[-4:]!=bytearray('\r\n\r\n','utf-8'):
     data+=self.rfile.read(1)
     lenn-=1
    toread=lenn-blen
    fn=uqu(data.decode().replace('+',' ')).split('filename',1)[1].split('"')[1]
    file=fn
    fn='.'+self.path+file
    tosave=0
    while os.path.exists(fn):
     tosave+=1
     fn='.'+self.path+str(tosave)+file
    a=l(open('0/...').read())
    a[fn]=toread
    open('0/...','w').write(str(a).replace("'",'"'))
    open(fn,'w').close()
    a=open(fn,'ab')
    rsize=1024
    while toread>0:
     read=min(toread,rsize,102400)
     toread-=read
     ti=time.time()
     a.write(self.rfile.read(read))
     rsize=int(min(rsize/(time.time()-ti)+1,2**22))
    self.rfile.read(blen)
  elif self.headers['fn']:
   name=self.headers['fn']
   name=name[:-1].split('a')
   name=[chr(int(w)) for w in name]
   name=''.join(name)
   if 1:
    toread=lenn
    file=name
    fn='.'+self.path+file
    tosave=0
    while os.path.exists(fn):
     tosave+=1
     fn='.'+self.path+str(tosave)+file
    a=l(open('0/...').read())
    a[fn]=toread
    open('0/...','w').write(str(a).replace("'",'"'))
    open(fn,'w').close()
    a=open(fn,'ab')
    rsize=1024
    while toread>0:
     read=min(toread,rsize,102400)
     toread-=read
     ti=time.time()
     a.write(self.rfile.read(read))
     rsize=max(int(min(rsize/(time.time()-ti),2**22)),1)
  else:
    data=self.rfile.read(lenn)
    data=data.decode().replace('+',' ')
    data=uqu(data)
    dec,data=data.split('=',1)
    if dec=='c':
     open('clip','w').write(data)
    if dec=='a':
     s=' '.join(time.asctime().split(':')).split()
     s0=str((int(s[2])+int(s[4]))%100)+s[3][-1]
     print(s0)
     a1='qwertyuiop'
     a2='asdfghjkl1'
     a3='zxcvbnm098'
     s1=a1[int(s0[0])]
     s2=a2[int(s0[1])]
     s3=a3[int(s0[2])]
     pas=(s1+s2+s3)*((int(s[3][-1])+int(s[4][-1]))//3+1)
     print(pas)
     if data==pas:
      admin=2
    if dec=='e':
     admin=1

  self.send_response(200)
  self.send_header("Content-type", "text/html; charset=utf-8")
  self.end_headers()
  self.wfile.write(bytes('''
     <html>
     <head>
    <meta http-equiv="refresh" content="1;URL=.">
    </meta>
    </head>
    <body>
    <style type=text/css>
    #neko {position: fixed; top:0; botom:0; left:0; right:0}
    #main {position: absolute; top:0; left:0}
    wi {background: #00ff00}
    </style>
    <div id="neko">
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"><br>
    <img src="'''+img+'''" width="100%"></div>
    </body>
    </html>
    ''', "utf-8"))