Created
June 20, 2018 09:30
-
-
Save AliYmn/c4315f687599276a2fcaeb878675db27 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render,HttpResponse | |
from instagram import inst | |
from django.db import connection | |
from threading import Thread | |
#from django.views.decorators.csrf import csrf_exempt | |
import ftplib | |
import time | |
from django.views.decorators.clickjacking import xframe_options_exempt | |
# Create your views here. | |
#@csrf_exempt | |
@xframe_options_exempt | |
def index(request): | |
if(request.GET): | |
agent = inst.Agent() | |
postkodu = str(request.GET['p_code']) | |
cekid = int(request.GET['p_id']) | |
yorsai = int(request.GET['p_comments']) | |
seckey = str(request.GET['p_seckey']) | |
cursor = connection.cursor() | |
cursor.execute("SELECT id FROM `cekilisler` WHERE `seckey` = '"+seckey+"' and durum !='Hazir'") | |
numrows = cursor.rowcount | |
connection.close() | |
if(numrows==1): | |
code = inst.Media(postkodu) | |
comments, after = agent.getComments(code, count=yorsai) | |
content = [] | |
ilave = "INSERT INTO liste (`katilimci`, `yorumu`, `yorumid`, `cekilisid`) VALUES" | |
ilave = ilave +'\n' | |
content.append(ilave) | |
titi=0 | |
for i in comments: | |
titi=titi+1 | |
ourum=str(i.text) | |
sinos = ourum.replace("'", "") | |
yorum=sinos.replace(",", " ") | |
corum=yorum.replace(";", " ") | |
string = "('" + str(i.owner) + "','" + corum + "','" + str(i.id) + "','" + str(cekid) + "')," | |
yazi = string.encode("ascii", errors='ignore') | |
yazim = str(yazi) | |
tersim = yazim.replace("\\'", "\'") | |
kesim = tersim.replace('b"', '') | |
yesim = kesim.replace("b'(", "(") | |
besim = yesim.replace('"', '') | |
cisim = besim.replace("),'", "),") | |
#cisim = cisim+'\n' | |
content.append(cisim) | |
ilavem = ";" | |
#ilavem = ilavem +'\n' | |
content.append(ilavem) | |
#filename = "{}.txt".format(postkodu) | |
#response = HttpResponse(content, content_type='text/plain') | |
#response['Content-Disposition'] = 'inline; filename={0}'.format(filename) | |
sonhal=''.join(content) | |
tirto = sonhal.replace("),;", ");") | |
cursor = connection.cursor() | |
cursor.execute("UPDATE `cekilisler` SET `durum` = 'Hazir' WHERE `id` = "+str(cekid)) | |
cursor.execute(tirto) | |
connection.commit() | |
connection.close() | |
dosya = open(postkodu+".txt", "w") | |
dosya.write(tirto) | |
dosya.close() | |
server = 'ftp.instacekilis.com' | |
username = '[email protected]' | |
password = 'apex1555...' | |
ftp_connection = ftplib.FTP(server, username, password) | |
remote_path = "/public_html/instacekilis.com/listeler/" | |
ftp_connection.cwd(remote_path) | |
fh = open(postkodu+'.txt','rb') | |
ftp_connection.storbinary('STOR '+postkodu+'.txt', fh) | |
fh.close() | |
sonuc=str("tebrikler!.. yorum cekme islemi tamamlandi. bu pencereyi kapat butonuna basip kapatiniz.") | |
response = HttpResponse(sonuc, content_type='text/plain') | |
return response | |
#thread_m = Thread(target=index,) | |
#thread_m.start() | |
return render(request,'index.html',locals()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment