Friday, April 15, 2022

Telegram - Export Members of a Public Group

There are two conditions to export group members of a telegram public group.

    1) It should be a Public group but you do not need to be an administrator or owner of the group, You can import / export members of any public group, just you should be a member of the group.

    2) If a member has selected ‘My Contacts’ option in ‘who can add you to groups and channels’ then you should be added in his/her contact list, only then you can import him/her into a group.

To export group members, First Generate api id and api hash in your telegram account. To do this, open my.telegram.org
Login using your registered phone number.
Now Open Link Development Tools and copy your api id and hash
We will use the api id and hash in the Python Script

 Create virtual environment with python 3 and install Telethon using pip.

virtualenv telegram -p /usr/bin/python3
source telegram/bin/activate
pip install Telethon==1.23.0

Update API ID, API hash and telegram registered phone number in the following python script export.py.

from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty
import csv

api_id = 9999999
api_hash = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
phone = '+919999999999'
client = TelegramClient(phone, api_id, api_hash)

client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone, input('Enter the code: '))


chats = []
last_date = None
chunk_size = 200
groups=[]
 
result = client(GetDialogsRequest(
             offset_date=last_date,
             offset_id=0,
             offset_peer=InputPeerEmpty(),
             limit=chunk_size,
             hash = 0
         ))
chats.extend(result.chats)

for chat in chats:
    try:
        if chat.megagroup== True:
            groups.append(chat)
    except:
        continue

print('Choose a group to scrape members from:')
i=0
for g in groups:
    print(str(i) + '- ' + g.title)
    i+=1

g_index = input("Enter a Number: ")
target_group=groups[int(g_index)]

print('Fetching Members...')
all_participants = []
all_participants = client.get_participants(target_group)
print('Saving In file...')
with open("members.csv","w",encoding='UTF-8') as f:
    writer = csv.writer(f,delimiter=",",lineterminator="\n")
    writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
    for user in all_participants:
        if user.username:
            username= user.username
        else:
            username= ""
        if user.first_name:
            first_name= user.first_name
        else:
            first_name= ""
        if user.last_name:
            last_name= user.last_name
        else:
            last_name= ""
        name= (first_name + ' ' + last_name).strip()
        writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])      
print('Members scraped successfully.')

Run the Python script in the same virtual env.

python export.py

It will list all your public groups. Choose number whose members you want to export.

It will export all group members by creating members.csv in the same directory.

cat members.csv

To see the steps : 


 

Telegram Import Group Members : 

https://linuxamination.blogspot.com/2022/04/telegram-import-members-of-public-group.html

Saturday, April 2, 2022

Solve FloodWaitError in Telegram Export Group Python Script

Your export group python script was working fine but recently you tried to export members of one of your public group and it is showing following error.

telethon.errors.common.MultiError: ([None, FloodWaitError('A wait of 30 seconds is required (caused by GetParticipantsRequest)')
Solution :

You need to make one change in your export script.

Remove 

aggressive=True

from the line

all_participants = client.get_participants(target_group, aggressive=True)

Above line should be appeared like this

all_participants = client.get_participants(target_group)

and you will not get the following FloodWaitError anymore.

Traceback (most recent call last):
  File "exportgroup.py", line 49, in <module>
    all_participants = client.get_participants(target_group, aggressive=True)
  File "virtualenvs/telegram/lib/python3.8/site-packages/telethon/sync.py", line 39, in syncified
    return loop.run_until_complete(coro)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "virtualenvs/telegram/lib/python3.8/site-packages/telethon/client/chats.py", line 503, in get_participants
    return await self.iter_participants(*args, **kwargs).collect()
  File "virtualenvs/telegram/lib/python3.8/site-packages/telethon/requestiter.py", line 113, in collect
    async for message in self:
  File "virtualenvs/telegram/lib/python3.8/site-packages/telethon/requestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "virtualenvs/telegram/lib/python3.8/site-packages/telethon/client/chats.py", line 221, in _load_next_chunk
    results = await self.client(self.requests)
  File "virtualenvs/telegram/lib/python3.8/site-packages/telethon/client/users.py", line 30, in __call__
    return await self._call(self._sender, request, ordered=ordered)
  File "virtualenvs/telegram/lib/python3.8/site-packages/telethon/client/users.py", line 75, in _call
    raise MultiError(exceptions, results, requests)
telethon.errors.common.MultiError: ([None, FloodWaitError('A wait of 30 seconds is required (caused by GetParticipantsRequest)'), FloodWaitError('A wait of 30 seconds is required (caused by GetParticipantsRequest)')

 

To see the steps :

 



Thursday, March 3, 2022

Themosis Framework - Laravel based wordpress setup on localhost

1) Download existing code and database and put code into htdocs and import sql file or if it is new setup, follow this url.

https://framework.themosis.com/docs/2.0/installation/

2) If wp_options has different domain on production, Use same domain in virtualhost for local setup. 

3) Point the domain upto htdocs (folder inside project root dir) and open it in browser.

4) If you get error

Unable to define the environment. / Unable to locate your environment configuration file. / Missing environment variables. / Error establishing a database connection
Solution :
Add your server's hostname in xyz.com/config/environment.php as a production value. In my case it is localserver.
<?php
return array(

    'local'         => ['xyz.local', 'xyz2.local'],
    'staging'       => 'dev.xyz.co.uk',
    'production'    => ['ip-172-16-150-95.eu-west-1.compute.internal', 'ip-172-31-13-11.eu-west-1.compute.internal', 'localserver']
);

5) Now if you get db connection error 'Error establishing a database connection'
Put correct database credentials and correct urls in xyz.com/.env.production.php
<?php
return [
    'DB_NAME'                       => 'xyz',
    'DB_USER'                       => 'admin',
    'DB_PASSWORD'                   => 'password',
    'DB_HOST'                       => 'localhost',
    'WP_HOME'                       => 'http://xyz.com',
    'WP_SITEURL'                    => 'http://
xyz.com/cms',
    'DEV_EMAIL'                     => 'developer@xyz.co.uk',
    'DEV_NAME'                      => '
developer',
]

6) If errors are resolved but it opens blank page in place of site, change owner of complete project to apache or www-data depends on it is centos or ubuntu.
sudo chown -R apache:apache xyz.com
It is not able to create files in xyz.com/storage/views, that's why you are getting blank page once necessary files are created, site can be opened.

7) After doing all above things but still you get 'Error establishing a database connection'. Check if you have created wp-config.php inside cms folder.
This creation is the reason of database connection error. There should be only one wp-config.php and it is in xyz.com/htdocs/wp-config.php
wp-admin Details :

http://xyz.co.in/cms/wp-login.php
Username - admin
Password - xxxxxxxxxxxxx
8) Fix issue 'Error establishing a database connection' in existing setup.
cd xyz.com          
nano config/environment.php
Remove same domain from staging and production.
nano .env.production.php
Make credentials and DB Variable correct.
rm htdocs/cms/wp-config.php
nano config/environment.php  
chown -R apache:apache storage/views/